python基于SQLAchemy的DBtools
时间:2021-07-01 10:21:17
帮助过:11人阅读
sqlalchemy
import create_engine
from sqlalchemy.orm
import sessionmaker
BIZ_DB = {
"dbusr":
"test",
"dbpasswd":
"123456",
"dburl":
"127.0.0.1:3306",
"dbname":
"test"}
OFFLINE_DB = {
"dbusr":
"test",
"dbpasswd":
"123456",
"dburl":
"127.0.0.1:3306",
"dbname":
"test"}
def create_session(dbusr,dbpasswd,dburl,dbname):
engine = create_engine(
"mysql+pymysql://{}:{}@{}/{}".format(dbusr,dbpasswd,dburl,dbname))
DBsession = sessionmaker(bind=
engine)
session =
DBsession()
return session
def create_session_biz():
dbusr = BIZ_DB[
"dbusr"]
dbpasswd = BIZ_DB[
"dbpasswd"]
dburl = BIZ_DB[
"dburl"]
dbname = BIZ_DB[
"dbname"]
return create_session(dbusr,dbpasswd,dburl,dbname)
def create_session_offline():
dbusr = OFFLINE_DB[
"dbusr"]
dbpasswd = OFFLINE_DB[
"dbpasswd"]
dburl = OFFLINE_DB[
"dburl"]
dbname = OFFLINE_DB[
"dbname"]
return create_session(dbusr, dbpasswd, dburl, dbname)
python基于SQLAchemy的DBtools
标签:imp pass from color port make mysql post turn