mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-23 22:29:34 -05:00
Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
15 lines
292 B
Python
15 lines
292 B
Python
class MySuperContextManager:
|
|
def __init__(self):
|
|
self.db = DBSession()
|
|
|
|
def __enter__(self):
|
|
return self.db
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
self.db.close()
|
|
|
|
|
|
async def get_db():
|
|
with MySuperContextManager() as db:
|
|
yield db
|