19 lines
485 B
Python

from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from loader import SECRETS
engine = create_async_engine(SECRETS.postgres_url, max_overflow=-1)
async_session = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)
async def get_session() -> AsyncSession:
"""Получение сессии БД
Returns:
AsyncSession
"""
async with async_session() as session:
return session