session.py 402 B

1234567891011
  1. from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine, AsyncSession
  2. from backend.app.core.config import settings
  3. engine = create_async_engine(settings.database_url, pool_pre_ping=True)
  4. SessionLocal = async_sessionmaker(bind=engine, class_=AsyncSession, expire_on_commit=False)
  5. async def get_db() -> AsyncSession:
  6. async with SessionLocal() as session:
  7. yield session