ratingprocess/Utils/DataBase/SqlAlchemyUtils.py

26 lines
598 B
Python

import json
import os
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
# Import DBConfig
with open(os.path.abspath(os.path.dirname(__file__) + '/DBConfig.json')) as f:
db_configs = json.load(f)
this_mysql_cfg = db_configs['Mysql']["wr_model_store"]
# Sqlalchemy Export
engine = create_engine(this_mysql_cfg)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db():
try:
db = Session()
yield db
finally:
db.close()