Modified files
storeapi/main.py
---
+++
@@ -1,5 +1,16 @@
+from contextlib import asynccontextmanager
+
from fastapi import FastAPI
+from storeapi.database import database
from storeapi.routers.posts import router as posts_router
-app = FastAPI()
+
+@asynccontextmanager
+async def lifespan(app: FastAPI):
+ await database.connect()
+ yield
+ await database.disconnect()
+
+app = FastAPI(lifespan=lifespan)
app.include_router(posts_router)
+