sqlalchemy-query-helpers 1.0.9__tar.gz → 1.0.101__tar.gz
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-1.0.9/src/sqlalchemy_query_helpers.egg-info → sqlalchemy_query_helpers-1.0.101}/PKG-INFO +1 -1
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/pyproject.toml +1 -1
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/src/sqlalchemy_query_helpers/main.py +15 -4
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101/src/sqlalchemy_query_helpers.egg-info}/PKG-INFO +1 -1
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/LICENSE +0 -0
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/README.md +0 -0
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/setup.cfg +0 -0
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/src/sqlalchemy_query_helpers/__init__.py +0 -0
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/src/sqlalchemy_query_helpers.egg-info/SOURCES.txt +0 -0
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/src/sqlalchemy_query_helpers.egg-info/dependency_links.txt +0 -0
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/src/sqlalchemy_query_helpers.egg-info/requires.txt +0 -0
- {sqlalchemy_query_helpers-1.0.9 → sqlalchemy_query_helpers-1.0.101}/src/sqlalchemy_query_helpers.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sqlalchemy-query-helpers
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.101
|
|
4
4
|
Summary: Some helpers for SQLAlchemy
|
|
5
5
|
Author-email: vladiscripts <blagopoluchie12@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/vladiscripts/sqlalchemy-query-helpers
|
|
@@ -27,7 +27,8 @@ class DB:
|
|
|
27
27
|
self.name = self.engine.url.database
|
|
28
28
|
|
|
29
29
|
def __del__(self):
|
|
30
|
-
self.session
|
|
30
|
+
if self.session:
|
|
31
|
+
self.session.close()
|
|
31
32
|
|
|
32
33
|
@staticmethod
|
|
33
34
|
def make_engine_str(use_os_env) -> str:
|
|
@@ -224,15 +225,25 @@ class DB:
|
|
|
224
225
|
self.session.commit()
|
|
225
226
|
return is_updated, is_inserted
|
|
226
227
|
|
|
227
|
-
def upsert(self, t, rows: Union[list[dict], tuple[dict]], mfields=None, do_commit=True):
|
|
228
|
+
def upsert(self, t, rows: Union[list[dict], tuple[dict]], mfields=None, do_commit=True, filter_unque_primary_keys=True):
|
|
228
229
|
rows_to_insert = [self.__to_dict(row, mfields) for row in rows]
|
|
229
230
|
stmt = insert(t).values(rows_to_insert)
|
|
230
|
-
|
|
231
|
+
# need to remove primary or unique keys on using, else will error
|
|
232
|
+
if filter_unque_primary_keys:
|
|
233
|
+
update_dict = {x.name: x for x in stmt.inserted for c in t._sa_class_manager.mapper.columns._all_columns
|
|
234
|
+
if x.name == c.name and c.unique is not True and c.primary_key is not True}
|
|
235
|
+
else:
|
|
236
|
+
update_dict = {x.name: x for x in stmt.inserted}
|
|
237
|
+
if not update_dict:
|
|
238
|
+
return
|
|
231
239
|
upsert_query = stmt.on_duplicate_key_update(update_dict)
|
|
232
240
|
with self.Session() as session:
|
|
233
241
|
session.execute(upsert_query)
|
|
234
242
|
if do_commit:
|
|
235
|
-
|
|
243
|
+
try:
|
|
244
|
+
session.commit()
|
|
245
|
+
except Exception as e:
|
|
246
|
+
session.rollback()
|
|
236
247
|
|
|
237
248
|
# def upsert(self, t, row, mfields=None):
|
|
238
249
|
# row = self.to_dict(row, mfields)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sqlalchemy-query-helpers
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.101
|
|
4
4
|
Summary: Some helpers for SQLAlchemy
|
|
5
5
|
Author-email: vladiscripts <blagopoluchie12@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/vladiscripts/sqlalchemy-query-helpers
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|