-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMssqlHelper.py
32 lines (29 loc) · 1.3 KB
/
MssqlHelper.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
# StandarClass
from sqlalchemy import create_engine
from pathlib import Path
import json
def getEngineFromConfig(config_file):
if Path(config_file).exists():
with open(config_file, 'r') as f:
config_json = json.load(f)
user = config_json['authentication']['user']
password = config_json['authentication']['password']
host = config_json['authentication']['host']
database = config_json['authentication']['database']
conn_str = 'mssql+pymssql://'+user+':'+password+'@'+host+'/'+database
return create_engine(conn_str)
def getEngineFromConfigWithUserAndPassword(config_file, user, password):
if Path(config_file).exists():
with open(config_file, 'r') as f:
config_json = json.load(f)
host = config_json['authentication']['host']
database = config_json['authentication']['database']
conn_str = 'mssql+pymssql://'+user+':'+password+'@'+host+'/'+database
return create_engine(conn_str)
def getEngineFromJson(config_json):
user = config_json['authentication']['user']
password = config_json['authentication']['password']
host = config_json['authentication']['host']
database = config_json['authentication']['database']
conn_str = 'mssql+pymssql://'+user+':'+password+'@'+host+'/'+database
return create_engine(conn_str)