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()