-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
24 lines (21 loc) · 833 Bytes
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -*- coding: utf-8 -*-
from Config import Config
from sqlalchemy import create_engine
def get_dbengine():
dbconfig = Config().get_config()['db']
if dbconfig['driver'] == 'postgresql':
proto = 'postgresql://'
elif dbconfig['driver'] == 'mysql':
proto = 'mysql://'
else:
proto = 'sqlite:///'
if dbconfig['driver'] in ('mysql', 'postgresql'):
engine = create_engine(proto + dbconfig['user'] + ':'
+ dbconfig['pass'] + '@' + dbconfig['host'] + ':'
+ dbconfig['port'] + '/' + dbconfig['database'])
elif dbconfig['driver'] == 'sqlite':
engine = create_engine(proto + dbconfig['sqlite'])
# use local gs05.sqlite as fallback
else:
engine = create_engine(proto + 'gs05.sqlite')
return engine