-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_init.py
39 lines (30 loc) · 967 Bytes
/
db_init.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
from data import db_session
import sqlalchemy as sa
from data.__all_models import *
from data.db_types import MYSQL, SQLITE
TYPE = MYSQL
# TYPE = SQLITE
def connect(type):
def mysql():
pass
db_path = "easydrop"
try:
with open("data/db_config") as f:
username, password = f.readline().split()
except FileNotFoundError:
raise FileNotFoundError("Create file with name db_config in root with username and password to "
"database separated with space")
else:
db_session.global_init(db_path, TYPE, username, password)
def sqlite():
db_dir = "db"
import os
db_path = os.path.join(db_dir, "easy-drop.sqlite")
if not os.path.exists(db_dir):
os.mkdir(db_dir)
db_session.global_init(db_path, TYPE)
{
MYSQL: mysql,
SQLITE: sqlite
}.get(type)()
connect(TYPE)