From b5f8e69b8aaefc093eabb3163eb0dd6445682a8b Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Sun, 3 Oct 2021 10:22:34 -0700 Subject: [PATCH] feat(FastAPI): use SQLAlchemy's scoped_session Closes #113 Signed-off-by: Kevin Morris --- aurweb/db.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aurweb/db.py b/aurweb/db.py index ea6b6918..2b934300 100644 --- a/aurweb/db.py +++ b/aurweb/db.py @@ -3,6 +3,7 @@ import math import re from sqlalchemy import event +from sqlalchemy.orm import scoped_session import aurweb.config import aurweb.util @@ -167,7 +168,8 @@ def get_engine(echo: bool = False): connect_args=connect_args, echo=echo) - Session = sessionmaker(autocommit=True, autoflush=False, bind=engine) + Session = scoped_session( + sessionmaker(autocommit=True, autoflush=False, bind=engine)) session = Session() if db_backend == "sqlite":