소스 검색

Update db.py

Timothy J. Baek 10 달 전
부모
커밋
37a5d2c06b
1개의 변경된 파일11개의 추가작업 그리고 0개의 파일을 삭제
  1. 11 0
      backend/apps/webui/internal/db.py

+ 11 - 0
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()