Zlovoblachko's picture
Add application file
339f372
raw
history blame
398 Bytes
from contextlib import asynccontextmanager
from .models import async_session
@asynccontextmanager
async def get_session():
"""Provide a transactional scope around a series of operations."""
session = async_session()
try:
yield session
await session.commit()
except Exception:
await session.rollback()
raise
finally:
await session.close()