server.web.db.deps

FastAPI dependency injection for database sessions.

This module provides the database session dependency for route handlers. Sessions are created from the sessionmaker stored in app.state by the db_lifespan context manager.

Attributes

DB

Dialect

Functions

get_db(→ Generator[sqlalchemy.orm.Session, None, None])

Yield a SQLAlchemy Session for FastAPI dependency injection.

get_dialect(→ str)

Get the database dialect name from app state.

Module Contents

server.web.db.deps.get_db(request: fastapi.Request) Generator[sqlalchemy.orm.Session, None, None]

Yield a SQLAlchemy Session for FastAPI dependency injection.

The session is automatically committed on success, rolled back on exception, and closed when the request completes.

Parameters:

request – The FastAPI request object (provides access to app.state)

Yields:

Session – A SQLAlchemy session bound to the application’s engine

server.web.db.deps.get_dialect(request: fastapi.Request) str

Get the database dialect name from app state.

Parameters:

request – The FastAPI request object

Returns:

The dialect name (e.g., ‘mysql’, ‘sqlite’, ‘postgresql’)

Return type:

str

server.web.db.deps.DB
server.web.db.deps.Dialect