traefik-confman/api/schema/extensions.py
2022-05-29 00:31:32 +02:00

15 lines
335 B
Python

from strawberry.extensions import Extension
from api.database import SessionLocal
class SQLAlchemySession(Extension):
def on_request_start(self):
self.execution_context.context["db"] = SessionLocal()
def on_request_end(self):
self.execution_context.context["db"].close()
extensions = (SQLAlchemySession,)