26 lines
702 B
Python
26 lines
702 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm.session import Session
|
|
|
|
from models.jvsmodels import Base
|
|
|
|
|
|
class MySQLSession(Session):
|
|
"""docstring for MySQLSession"""
|
|
def __init__(self, settings):
|
|
self.engine = create_engine(
|
|
'mysql+pymysql://{user}:{passwd}@{host}:{port}/{db}?charset=utf8mb4'.format(**settings))
|
|
super(MySQLSession, self).__init__(bind=self.engine)
|
|
|
|
def create_db(self):
|
|
Base.metadata.create_all(self.engine)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import yaml
|
|
with open("config.yml", 'r') as ymlfile:
|
|
cfg = yaml.load(ymlfile)
|
|
|
|
session = MySQLSession(cfg['mysql'])
|
|
session.create_db()
|