14 lines
457 B
Python
14 lines
457 B
Python
from collections.abc import AsyncGenerator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
|
|
from app.core.config import settings
|
|
|
|
engine = create_async_engine(settings.database_url, pool_pre_ping=True)
|
|
async_session_factory = async_sessionmaker(engine, expire_on_commit=False)
|
|
|
|
|
|
async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
|
async with async_session_factory() as session:
|
|
yield session
|