26 lines
562 B
Python
26 lines
562 B
Python
from collections.abc import AsyncIterator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
|
|
from app.config.settings import settings
|
|
|
|
|
|
engine = create_async_engine(
|
|
settings.postgres_dsn,
|
|
echo=settings.debug,
|
|
pool_pre_ping=True,
|
|
)
|
|
|
|
AsyncSessionLocal = async_sessionmaker(
|
|
bind=engine,
|
|
class_=AsyncSession,
|
|
autoflush=False,
|
|
autocommit=False,
|
|
expire_on_commit=False,
|
|
)
|
|
|
|
|
|
async def get_db() -> AsyncIterator[AsyncSession]:
|
|
async with AsyncSessionLocal() as session:
|
|
yield session
|