"""Async-Engine und Session-Factory.""" from collections.abc import AsyncGenerator from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine from app.core.config import settings engine = create_async_engine( str(settings.database_url), echo=settings.debug, pool_pre_ping=True, ) SessionLocal = async_sessionmaker( bind=engine, class_=AsyncSession, expire_on_commit=False, autoflush=False, ) async def get_session() -> AsyncGenerator[AsyncSession, None]: """FastAPI-Dependency: eine Session pro Request.""" async with SessionLocal() as session: try: yield session except Exception: await session.rollback() raise