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
|