"""Async SQLAlchemy engine/session for PM database.""" from collections.abc import AsyncIterator from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine from app.config import settings try: engine = create_async_engine(settings.DATABASE_URL, pool_pre_ping=True, pool_size=5, max_overflow=5) except Exception: # Fallback for testing environments or when asyncpg driver is not installed on host engine = create_async_engine("sqlite+aiosqlite:///:memory:") SessionFactory = async_sessionmaker(engine, expire_on_commit=False) async def get_db() -> AsyncIterator[AsyncSession]: async with SessionFactory() as session: yield session