-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.py
More file actions
29 lines (22 loc) · 865 Bytes
/
Copy pathengine.py
File metadata and controls
29 lines (22 loc) · 865 Bytes
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
"""Engine Builder."""
from sqlalchemy import create_engine
def _create_engine(engine, autocommit=True):
"""Return an engine from standard format."""
base_con_str = (
'{dialect}+{driver}://{username}:{password}@{host}'
':{port}/{database}').format(**engine)
return create_engine(
base_con_str,
execution_options=dict(autocommit=autocommit))
class SqlClient(object):
"""SQL Client for any engine in ENGINES.
>>> redshift = SqlClient('REDSHIFT')
>>> viewer = redshift.sql_client()
>>> viewer('select * from table;')
"""
def __init__(self, engine, autocommit=True):
"""Just need engine from ENGINES object."""
self.engine = _create_engine(engine, autocommit)
def sql_client(self):
"""Convenience function to view query results."""
return self.engine.execute