language-learning-app/api/app/outbound/postgres/database.py

17 lines
435 B
Python
Raw Permalink Normal View History

2026-03-18 20:55:02 +00:00
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from sqlalchemy.orm import DeclarativeBase
from ...config import settings
2026-03-18 20:55:02 +00:00
engine = create_async_engine(settings.database_url)
AsyncSessionLocal = async_sessionmaker(engine, expire_on_commit=False)
class Base(DeclarativeBase):
pass
async def get_db() -> AsyncSession:
2026-03-18 20:55:02 +00:00
async with AsyncSessionLocal() as session:
yield session