From 37a5d2c06b78098ed70f52e9fefdc824ad96d531 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 3 Jul 2024 23:32:46 -0700 Subject: [PATCH] Update db.py --- backend/apps/webui/internal/db.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/apps/webui/internal/db.py b/backend/apps/webui/internal/db.py index 320ab3e07..bfdc52c11 100644 --- a/backend/apps/webui/internal/db.py +++ b/backend/apps/webui/internal/db.py @@ -53,8 +53,19 @@ if "sqlite" in SQLALCHEMY_DATABASE_URL: ) else: engine = create_engine(SQLALCHEMY_DATABASE_URL, pool_pre_ping=True) + + SessionLocal = sessionmaker( autocommit=False, autoflush=False, bind=engine, expire_on_commit=False ) Base = declarative_base() Session = scoped_session(SessionLocal) + + +# Dependency +def get_db(): + db = SessionLocal() + try: + yield db + finally: + db.close()