datamarket 0.9.7__py3-none-any.whl → 0.9.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of datamarket might be problematic. Click here for more details.
- datamarket/interfaces/alchemy.py +39 -5
- {datamarket-0.9.7.dist-info → datamarket-0.9.8.dist-info}/METADATA +1 -1
- {datamarket-0.9.7.dist-info → datamarket-0.9.8.dist-info}/RECORD +5 -5
- {datamarket-0.9.7.dist-info → datamarket-0.9.8.dist-info}/LICENSE +0 -0
- {datamarket-0.9.7.dist-info → datamarket-0.9.8.dist-info}/WHEEL +0 -0
datamarket/interfaces/alchemy.py
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import logging
|
|
5
5
|
from urllib.parse import quote_plus
|
|
6
6
|
|
|
7
|
-
from sqlalchemy import DDL, create_engine
|
|
7
|
+
from sqlalchemy import DDL, create_engine, text
|
|
8
8
|
from sqlalchemy.exc import IntegrityError
|
|
9
9
|
from sqlalchemy.orm import sessionmaker
|
|
10
10
|
|
|
@@ -14,6 +14,13 @@ from sqlalchemy.orm import sessionmaker
|
|
|
14
14
|
logger = logging.getLogger(__name__)
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
class MockContext:
|
|
18
|
+
def __init__(self, column):
|
|
19
|
+
self.current_parameters = {}
|
|
20
|
+
self.current_column = column
|
|
21
|
+
self.connection = None
|
|
22
|
+
|
|
23
|
+
|
|
17
24
|
class AlchemyInterface:
|
|
18
25
|
def __init__(self, config):
|
|
19
26
|
if "db" in config:
|
|
@@ -28,10 +35,10 @@ class AlchemyInterface:
|
|
|
28
35
|
|
|
29
36
|
def get_conn_str(self):
|
|
30
37
|
return (
|
|
31
|
-
f
|
|
32
|
-
f
|
|
33
|
-
f
|
|
34
|
-
f
|
|
38
|
+
f"{self.config['engine']}://"
|
|
39
|
+
f"{self.config['user']}:{quote_plus(self.config['password'])}"
|
|
40
|
+
f"@{self.config['host']}:{self.config['port']}"
|
|
41
|
+
f"/{self.config['database']}"
|
|
35
42
|
)
|
|
36
43
|
|
|
37
44
|
@staticmethod
|
|
@@ -109,3 +116,30 @@ class AlchemyInterface:
|
|
|
109
116
|
logger.info(f"{alchemy_obj} already in db")
|
|
110
117
|
|
|
111
118
|
self.session.rollback()
|
|
119
|
+
|
|
120
|
+
def reset_column(self, query_results, column_name):
|
|
121
|
+
if not query_results:
|
|
122
|
+
logger.warning("No objects to reset column for.")
|
|
123
|
+
return
|
|
124
|
+
|
|
125
|
+
first_obj = query_results[0]
|
|
126
|
+
model_class = first_obj.__class__
|
|
127
|
+
table = model_class.__table__
|
|
128
|
+
|
|
129
|
+
if column_name not in table.columns:
|
|
130
|
+
logger.warning(f"Column {column_name} does not exist in table {table.name}.")
|
|
131
|
+
return
|
|
132
|
+
|
|
133
|
+
column = table.columns[column_name]
|
|
134
|
+
|
|
135
|
+
if column.server_default is not None:
|
|
136
|
+
query_results.update({column_name: text("DEFAULT")}, synchronize_session=False)
|
|
137
|
+
elif column.default is not None:
|
|
138
|
+
default_value = column.default.arg
|
|
139
|
+
if callable(default_value):
|
|
140
|
+
default_value = default_value(MockContext(column))
|
|
141
|
+
query_results.update({column_name: default_value}, synchronize_session=False)
|
|
142
|
+
else:
|
|
143
|
+
raise ValueError(f"Column '{column_name}' doesn't have a default value defined.")
|
|
144
|
+
|
|
145
|
+
self.session.commit()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
datamarket/__init__.py,sha256=FHS77P9qNewKMoN-p0FLEUEC60oWIYup1QkbJZP4ays,12
|
|
2
2
|
datamarket/interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
datamarket/interfaces/alchemy.py,sha256=
|
|
3
|
+
datamarket/interfaces/alchemy.py,sha256=9Guzsdy8k8tBsODeozQhuuXshxf3dMgERPVhuumiP2M,5427
|
|
4
4
|
datamarket/interfaces/aws.py,sha256=7KLUeBxmPN7avEMPsu5HC_KHB1N7W6Anp2X8fo43mlw,2383
|
|
5
5
|
datamarket/interfaces/drive.py,sha256=shbV5jpQVe_KPE-8Idx6Z9te5Zu1SmVfrvSAyd9ZIgE,2915
|
|
6
6
|
datamarket/interfaces/ftp.py,sha256=o0KlJxtksbop9OjCiQRzyAa2IeG_ExVXagS6apwrAQo,1881
|
|
@@ -17,7 +17,7 @@ datamarket/utils/main.py,sha256=O6rX-65h4h0j2zs9dofdTPlly5reKDnvgLtTwbLmbWg,6529
|
|
|
17
17
|
datamarket/utils/selenium.py,sha256=IMKlbLzXABFhACnWzhHmB0l2hhVzNwHGZwbo14nEewQ,2499
|
|
18
18
|
datamarket/utils/soda.py,sha256=eZTXFbI1P3WoMd1MM-YjoVTpdjTcDSWuvBb7ViBMhSQ,941
|
|
19
19
|
datamarket/utils/typer.py,sha256=FDF3l6gh3UlAFPsHCtesnekvct2rKz0oFn3uKARBQvE,814
|
|
20
|
-
datamarket-0.9.
|
|
21
|
-
datamarket-0.9.
|
|
22
|
-
datamarket-0.9.
|
|
23
|
-
datamarket-0.9.
|
|
20
|
+
datamarket-0.9.8.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
21
|
+
datamarket-0.9.8.dist-info/METADATA,sha256=Hokmy_KnaGN4bwDG4S2NjJRyYy2jNZd2ZkBq4hwA7Bc,6362
|
|
22
|
+
datamarket-0.9.8.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
23
|
+
datamarket-0.9.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|