-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.py
60 lines (44 loc) · 1.56 KB
/
base.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# coding=utf-8
#from sqlalchemy import *
import configparser
from sqlalchemy.orm import scoped_session
import pymysql
from sqlalchemy import *
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import json
import sqlalchemy
from sqlalchemy.types import TypeDecorator
SIZE = 256
# class TextPickleType(TypeDecorator):
# impl = sqlalchemy.Text(SIZE)
# def process_bind_param(self, value, dialect):
# if value is not None:
# value = json.dumps(value)
# return value
# def process_result_value(self, value, dialect):
# if value is not None:
# value = json.loads(value)
# return value
config = configparser.ConfigParser()
config.read('config.ini')
if (config['database']["engine"] == "sqlite"):
_DB_URI = 'sqlite:///' + \
config['database']["database"]+'.sqlite'+"?check_same_thread=False"
elif (config['database']["engine"] == "mariadb"):
_DB_URI = "mysql+pymysql://"+config['database']["user"]+":"+config['database']["password"] + \
"@"+config['database']["host"]+"/" + \
config['database']["database"]+"?charset=utf8mb4"
else:
print("volatile database")
_DB_URI = 'sqlite://'
if config["database"].getint("debug", 0) == 0:
engine = create_engine(_DB_URI)
else:
engine = create_engine(_DB_URI, echo=True,)
metadata = MetaData(bind=None)
#Session = sessionmaker(bind=engine)
session_factory = sessionmaker(bind=engine)
Session = scoped_session(session_factory)
Base = declarative_base()