b7e6f637a7
Consolidate API gateway service into monorepo. Squashed from https://github.com/cartsnitch/api main (89bacb1). Co-Authored-By: Paperclip <noreply@paperclip.ing>
17 lines
589 B
Python
17 lines
589 B
Python
"""Database session management for the API gateway."""
|
|
|
|
from collections.abc import AsyncGenerator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
|
|
from cartsnitch_api.config import settings
|
|
|
|
engine = create_async_engine(settings.database_url, echo=False)
|
|
async_session_factory = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
|
|
|
|
|
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|
"""FastAPI dependency that yields an async DB session."""
|
|
async with async_session_factory() as session:
|
|
yield session
|