From f1e1f1ee6fbbc5b9d7eaef500465552bb39df427 Mon Sep 17 00:00:00 2001 From: maruizhi <3088243241@qq.com> Date: Sun, 20 Sep 2026 14:21:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E8=A1=A8=E5=88=97=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/model/0022.py | 0 PythonProject/util/database.py | 9 ++++++++- tmpl/work/util/database.py | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) delete mode 100644 PythonProject/model/0022.py diff --git a/PythonProject/model/0022.py b/PythonProject/model/0022.py deleted file mode 100644 index e69de29..0000000 diff --git a/PythonProject/util/database.py b/PythonProject/util/database.py index bcdd5d7..7c72545 100644 --- a/PythonProject/util/database.py +++ b/PythonProject/util/database.py @@ -6,4 +6,11 @@ engine = create_engine(db_url,pool_size=50) Base = declarative_base() Session = sessionmaker(bind=engine,autoflush=False,autocommit=False) -db = Session() + +def get_db(): + db = Session() + try: + yield db + finally: + db.close() + diff --git a/tmpl/work/util/database.py b/tmpl/work/util/database.py index 3549783..dc0a500 100644 --- a/tmpl/work/util/database.py +++ b/tmpl/work/util/database.py @@ -6,3 +6,10 @@ engine = create_engine(db_url,pool_size=50) Base = declarative_base() Session = sessionmaker(bind=engine,autoflush=False,autocommit=False) + +def get_db(): + db = Session() + try: + yield db + finally: + db.close()