from typing import AsyncGenerator from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from configs.config import db_url DATABASE_URL = db_url Base = declarative_base() engine = create_async_engine(DATABASE_URL) async_session = sessionmaker( bind=engine, class_=AsyncSession, expire_on_commit=False, ) async def get_async_session() -> AsyncGenerator[AsyncSession, None]: async with async_session() as session: yield session