<!-- .github/pull_request_template.md --> ## Description <!-- Provide a clear description of the changes in this PR --> ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin. --------- Co-authored-by: Daulet Amirkhanov <damirkhanov01@gmail.com>
15 lines
471 B
Python
15 lines
471 B
Python
from typing import AsyncGenerator
|
|
from contextlib import asynccontextmanager
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from .get_relational_engine import get_relational_engine
|
|
|
|
|
|
@asynccontextmanager
|
|
async def get_async_session(auto_commit=False) -> AsyncGenerator[AsyncSession, None]:
|
|
db_engine = get_relational_engine()
|
|
async with db_engine.get_async_session() as session:
|
|
yield session
|
|
|
|
if auto_commit:
|
|
await session.commit()
|