Initial commit
This commit is contained in:
commit
351d98c523
36 changed files with 1836 additions and 0 deletions
26
pyjeeves/db.py
Normal file
26
pyjeeves/db.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# -*- 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}'.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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue