19 lines
524 B
Python
19 lines
524 B
Python
from typing import AsyncGenerator
|
|
|
|
from sqlalchemy.ext.asyncio import (AsyncSession, async_sessionmaker,
|
|
create_async_engine)
|
|
|
|
from fastfood.config import settings
|
|
|
|
async_engine = create_async_engine(settings.DATABASE_URL_asyncpg)
|
|
async_session_maker = async_sessionmaker(
|
|
async_engine,
|
|
class_=AsyncSession,
|
|
expire_on_commit=False,
|
|
)
|
|
|
|
|
|
async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
|
|
async with async_session_maker() as session:
|
|
yield session
|