23 lines
588 B
Python
23 lines
588 B
Python
from __future__ import annotations
|
|
|
|
from collections.abc import AsyncGenerator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
|
|
from cpv3.infrastructure.settings import get_settings
|
|
|
|
|
|
_settings = get_settings()
|
|
_engine = create_async_engine(
|
|
_settings.get_database_url(),
|
|
echo=_settings.debug,
|
|
pool_pre_ping=True,
|
|
)
|
|
|
|
SessionLocal = async_sessionmaker(bind=_engine, class_=AsyncSession, expire_on_commit=False)
|
|
|
|
|
|
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|
async with SessionLocal() as session:
|
|
yield session
|