15 lines
372 B
Python
15 lines
372 B
Python
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() |