Skip to content

db

Database connectivity and transaction management for the application.

async_session_factory module-attribute

async_session_factory: async_sessionmaker[AsyncSession] = async_sessionmaker(engine)

Database session factory.

See async_sessionmaker().

engine module-attribute

engine = create_async_engine(
    settings.db.URL,
    echo=settings.db.ECHO,
    echo_pool=settings.db.ECHO_POOL,
    json_serializer=_msgspec_json_encoder.encode,
    max_overflow=settings.db.POOL_MAX_OVERFLOW,
    pool_size=settings.db.POOL_SIZE,
    pool_timeout=settings.db.POOL_TIMEOUT,
    poolclass=NullPool if settings.db.POOL_DISABLE else None,
)

Database connection engine.

Configure via DatabaseSettings.

Overrides default JSON serializer to use msgspec.

See create_async_engine() for detailed instructions.