19 lines
585 B
Python
19 lines
585 B
Python
from collections.abc import AsyncGenerator
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
from app.core.config import get_settings
|
|
|
|
settings = get_settings()
|
|
|
|
engine = create_async_engine(settings.database_url, future=True, pool_pre_ping=True)
|
|
SessionLocal = async_sessionmaker(bind=engine, expire_on_commit=False, class_=AsyncSession)
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|
async with SessionLocal() as session:
|
|
yield session
|