File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change 22from routes .users import UserRouter
33from fastapi import FastAPI
44from database .database import engine
5+ from contextlib import asynccontextmanager
56
6-
7- app = FastAPI (description = "Template for building FastAPI applications with PostgreSQL" , contact = {"email" : "samanidarix@gmail.com" })
8-
9-
10-
11-
12- @app .on_event ("startup" )
13- async def startup ():
7+ @asynccontextmanager
8+ async def lifespan (app : FastAPI ):
149 await engine .connect ()
10+ yield
11+ # You can also close DB connections here if needed
12+ print ("App shutdown complete." )
13+ await engine .dispose ()
14+
1515
16- @app .on_event ("shutdown" )
17- async def shutdown ():
18- await engine .dispose ()
16+ app = FastAPI (lifespan = lifespan , description = "Template for building FastAPI applications with PostgreSQL" , contact = {"email" : "samanidarix@gmail.com" })
1917
2018
2119
You can’t perform that action at this time.
0 commit comments