mp_update/core/storage/base.py

18 lines
465 B
Python
Raw Normal View History

2024-05-20 13:52:52 +03:00
from contextlib import asynccontextmanager
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
class BaseStorage:
def __init__(self, session_maker: async_sessionmaker):
self.__session_maker: async_sessionmaker = session_maker
@asynccontextmanager
async def get_session(self) -> AsyncSession:
session = self.__session_maker()
try:
yield session
finally:
await session.aclose()