1
0
Fork 0
TakwayPlatform/app/dependencies/database.py

15 lines
372 B
Python
Raw Normal View History

2024-05-01 17:18:30 +08:00
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
from config import get_config
Config = get_config()
LocalSession = sessionmaker(autocommit=False, autoflush=False, bind=create_engine(Config.SQLALCHEMY_DATABASE_URI))
#返回一个数据库连接
def get_db():
db = LocalSession()
try:
yield db
finally:
db.close()