fmn.api.database module

async fmn.api.database.gen_db_session() Iterator[AsyncSession][source]

Generate database sessions for FastAPI request handlers.

This lets users declare the session as a dependency in request handler functions, e.g.:

@app.get("/path")
def process_path(db_session: AsyncSession = Depends(gen_db_session)):
    query = select(Model).filter_by(...)
    result = await db_session.execute(query)
    ...
Returns:

A sqlalchemy.ext.asyncio.AsyncSession object for the current request