Newer
Older
class SQL_Database():
def __init__(self):
config_path = Path("../config/")
with open(config_path / 'config.json', 'r') as fh:
config = json.load(fh)
self.driver = config['DRIVER']
self.server = config['SERVER']
self.database = config['DATABASE']
self.uid = config['UID']
self.pwd = config['PWD']
self.port = config['PORT']
self.encrypt = config['ENCRYPT']
def connect(self):
connection = pyodbc.connect(
f'Driver={self.driver};'
f'Server={self.server};'
f'Database={self.database};'
f'uid={self.uid};'
f'pwd={self.pwd};'
f'port={self.port};'
f'Encrypt={self.encrypt};'
)
return connection
# How to connect to the db?
# con = SQL_Database().connect()
# quest = con.execute("SELECT table_schema || '.' || table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');")
# row = quest.fetchone()
# print(row)
# quest.close()
# con.close()