24 lines
542 B
Python
24 lines
542 B
Python
from __future__ import annotations
|
|
from contextlib import contextmanager
|
|
from fastapi import Depends
|
|
from sqlalchemy.orm import Session
|
|
from ..engines import CRUDKitRuntime
|
|
|
|
_runtime = CRUDKitRuntime()
|
|
|
|
@contextmanager
|
|
def _session_scope():
|
|
SessionLocal = _runtime.session_factory
|
|
session: Session = SessionLocal()
|
|
try:
|
|
yield session
|
|
session.commit()
|
|
except Exception:
|
|
session.rollback()
|
|
raise
|
|
finally:
|
|
session.close()
|
|
|
|
def get_db():
|
|
with _session_scope() as s:
|
|
yield s
|