-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloader.py
25 lines (21 loc) · 799 Bytes
/
loader.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
class Loader:
def __init__(self, curser=None, table=None, tablename=None, format='csv'):
assert curser is not None, "No cursor created"
assert table is not None, "Table variable needed"
assert tablename is not None, "Table name is needed"
self._curser = curser
self._table = table
self._tablename = tablename
self._format = format
def load(self):
"""
load data into postgresql
:return:
"""
if self._format == 'csv':
self._curser.copy_expert(f"""COPY {self._tablename} FROM STDIN WITH (FORMAT CSV)""", self._table)
elif self._format == 'xlsx':
raise Exception("Capability not yet ready. Coming soon.")
else:
pass
return self._curser