-
-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathsqlalchemy_client.py
More file actions
35 lines (24 loc) · 780 Bytes
/
sqlalchemy_client.py
File metadata and controls
35 lines (24 loc) · 780 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
30
31
32
33
34
import sqlalchemy
import typing
class SQLAlchemyClient(object):
def __init__(self, connection_string :str):
self._connection_string :str = connection_string
self._eng = sqlalchemy.create_engine(connection_string)
def _exec_raw_query(self, query :str) -> typing.List[typing.Dict]:
r = self._eng.execute(query)
rv = []
try:
for row in r:
rv.append(row)
except Exception as err:
pass
return rv
def _run_raw_queries(self, queries :typing.List[str]) -> typing.List[typing.Dict]:
ret_val = []
for q in queries:
nv = self._exec_raw_query(q)
if nv:
ret_val += nv
return ret_val
def run_raw_queries(self, queries :typing.List[str]) -> typing.List:
return self._run_raw_queries(queries)