sqlalchemy-query-helpers 1.0.8__py3-none-any.whl → 1.0.10__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 sqlalchemy-query-helpers might be problematic. Click here for more details.
- sqlalchemy_query_helpers/main.py +13 -3
- {sqlalchemy_query_helpers-1.0.8.dist-info → sqlalchemy_query_helpers-1.0.10.dist-info}/METADATA +1 -1
- sqlalchemy_query_helpers-1.0.10.dist-info/RECORD +7 -0
- sqlalchemy_query_helpers-1.0.8.dist-info/RECORD +0 -7
- {sqlalchemy_query_helpers-1.0.8.dist-info → sqlalchemy_query_helpers-1.0.10.dist-info}/LICENSE +0 -0
- {sqlalchemy_query_helpers-1.0.8.dist-info → sqlalchemy_query_helpers-1.0.10.dist-info}/WHEEL +0 -0
- {sqlalchemy_query_helpers-1.0.8.dist-info → sqlalchemy_query_helpers-1.0.10.dist-info}/top_level.txt +0 -0
sqlalchemy_query_helpers/main.py
CHANGED
|
@@ -224,15 +224,25 @@ class DB:
|
|
|
224
224
|
self.session.commit()
|
|
225
225
|
return is_updated, is_inserted
|
|
226
226
|
|
|
227
|
-
def upsert(self, t, rows: Union[list[dict], tuple[dict]], mfields=None, do_commit=True):
|
|
227
|
+
def upsert(self, t, rows: Union[list[dict], tuple[dict]], mfields=None, do_commit=True, filter_unque_primary_keys=True):
|
|
228
228
|
rows_to_insert = [self.__to_dict(row, mfields) for row in rows]
|
|
229
229
|
stmt = insert(t).values(rows_to_insert)
|
|
230
|
-
|
|
230
|
+
# need to remove primary or unique keys on using, else will error
|
|
231
|
+
if filter_unque_primary_keys:
|
|
232
|
+
update_dict = {x.name: x for x in stmt.inserted for c in t._sa_class_manager.mapper.columns._all_columns
|
|
233
|
+
if x.name == c.name and c.unique is not True and c.primary_key is not True}
|
|
234
|
+
else:
|
|
235
|
+
update_dict = {x.name: x for x in stmt.inserted}
|
|
236
|
+
if not update_dict:
|
|
237
|
+
return
|
|
231
238
|
upsert_query = stmt.on_duplicate_key_update(update_dict)
|
|
232
239
|
with self.Session() as session:
|
|
233
240
|
session.execute(upsert_query)
|
|
234
241
|
if do_commit:
|
|
235
|
-
|
|
242
|
+
try:
|
|
243
|
+
session.commit()
|
|
244
|
+
except Exception as e:
|
|
245
|
+
session.rollback()
|
|
236
246
|
|
|
237
247
|
# def upsert(self, t, row, mfields=None):
|
|
238
248
|
# row = self.to_dict(row, mfields)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
sqlalchemy_query_helpers/__init__.py,sha256=xxmsXX2HKm1K8Ay9sy_tXGkPDWz3NXJI0s4xiwPckr0,39
|
|
2
|
+
sqlalchemy_query_helpers/main.py,sha256=bbKi3JQ6P6c0VuPF_3v1a2IKZZC2y6Z1BxhWUsHXqII,13159
|
|
3
|
+
sqlalchemy_query_helpers-1.0.10.dist-info/LICENSE,sha256=XUL1pa84eZAnKR9S2WnYrv2M523Oysejy3KPlVSyCks,1069
|
|
4
|
+
sqlalchemy_query_helpers-1.0.10.dist-info/METADATA,sha256=vHzOYUc9XB3JpY4waa3A-PYVznNv_ks5Ti5FvW3co00,2598
|
|
5
|
+
sqlalchemy_query_helpers-1.0.10.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
6
|
+
sqlalchemy_query_helpers-1.0.10.dist-info/top_level.txt,sha256=3CUM4jiTua2frHF1satgUAYlW0QfDsvdkxO_6Fj_0zY,25
|
|
7
|
+
sqlalchemy_query_helpers-1.0.10.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
sqlalchemy_query_helpers/__init__.py,sha256=xxmsXX2HKm1K8Ay9sy_tXGkPDWz3NXJI0s4xiwPckr0,39
|
|
2
|
-
sqlalchemy_query_helpers/main.py,sha256=WQkS85VCqwWPu26vPU2dflGG0fRsLXDKxzjCPni3rfo,12628
|
|
3
|
-
sqlalchemy_query_helpers-1.0.8.dist-info/LICENSE,sha256=XUL1pa84eZAnKR9S2WnYrv2M523Oysejy3KPlVSyCks,1069
|
|
4
|
-
sqlalchemy_query_helpers-1.0.8.dist-info/METADATA,sha256=z2g86HTnnfY4fORnltAX65cmVPR_aPg-L6FtcdhCeq8,2597
|
|
5
|
-
sqlalchemy_query_helpers-1.0.8.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
6
|
-
sqlalchemy_query_helpers-1.0.8.dist-info/top_level.txt,sha256=3CUM4jiTua2frHF1satgUAYlW0QfDsvdkxO_6Fj_0zY,25
|
|
7
|
-
sqlalchemy_query_helpers-1.0.8.dist-info/RECORD,,
|
{sqlalchemy_query_helpers-1.0.8.dist-info → sqlalchemy_query_helpers-1.0.10.dist-info}/LICENSE
RENAMED
|
File without changes
|
{sqlalchemy_query_helpers-1.0.8.dist-info → sqlalchemy_query_helpers-1.0.10.dist-info}/WHEEL
RENAMED
|
File without changes
|
{sqlalchemy_query_helpers-1.0.8.dist-info → sqlalchemy_query_helpers-1.0.10.dist-info}/top_level.txt
RENAMED
|
File without changes
|