Closed scheung38 closed 3 years ago
from the standard SQLALCHEMY there is db.connect() and db.disconnect() inside startup and shutdown event respectively, how to do it here thanks
api = FastAPI() api.add_middleware(DBSessionMiddleware, db_url=DATABASE_URL) @api.on_event("startup") async def startup(): await db.connected() <-- ? @api.on_event("shutdown") async def shutdown(): await db.disconnect() <--- replace with db.session.close_all() ?
A new session is created before each request and closed after each request.
So we don't need it here on startup and shutdown? As response seems slow when making FastAPI request
from the standard SQLALCHEMY there is db.connect() and db.disconnect() inside startup and shutdown event respectively, how to do it here thanks