14 lines
450 B
Python
14 lines
450 B
Python
from collections.abc import AsyncIterator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
|
|
from app.core.config import get_settings
|
|
|
|
engine = create_async_engine(get_settings().database_url, pool_pre_ping=True)
|
|
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)
|
|
|
|
|
|
async def get_db() -> AsyncIterator[AsyncSession]:
|
|
async with async_session_maker() as session:
|
|
yield session
|