-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn.py
26 lines (22 loc) · 972 Bytes
/
conn.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
from json import load
from sqlalchemy import create_engine
from sqlalchemy.engine.url import URL
def run():
# Criando tabelas
with open("config.json") as jsonfile:
config = load(jsonfile)
env = config['env']
if env == "dev":
db_config = config['database_dev']
engine = create_engine(db_config['drivername'], echo=False)
if env == "prod":
db_config = config['database']
engine = create_engine(URL.create(
db_config['drivername'],
db_config['username'],
db_config['password'],
db_config['host'],
db_config['port'],
db_config['database']),
connect_args={'options': '-csearch_path={}'.format(db_config['schema'])})
return engine