ecodev-core 0.0.44__py3-none-any.whl → 0.0.45__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 ecodev-core might be problematic. Click here for more details.

ecodev_core/__init__.py CHANGED
@@ -44,7 +44,7 @@ from ecodev_core.db_upsertion import field
44
44
  from ecodev_core.db_upsertion import sfield
45
45
  from ecodev_core.db_upsertion import upsert_data
46
46
  from ecodev_core.db_upsertion import upsert_deletor
47
- from ecodev_core.db_upsertion import upsert_dict_data
47
+ from ecodev_core.db_upsertion import upsert_df_data
48
48
  from ecodev_core.db_upsertion import upsert_selector
49
49
  from ecodev_core.deployment import Deployment
50
50
  from ecodev_core.email_sender import send_email
@@ -102,5 +102,5 @@ __all__ = [
102
102
  'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile', 'upsert_new_user',
103
103
  'datify', 'safe_drop_columns', 'get_value', 'is_null', 'send_email', 'first_func_or_default',
104
104
  'sort_by_keys', 'sort_by_values', 'Settings', 'load_yaml_file', 'Deployment', 'Version',
105
- 'sfield', 'field', 'upsert_data', 'upsert_deletor', 'get_row_versions', 'get_versions',
106
- 'db_to_value', 'upsert_dict_data', 'upsert_selector']
105
+ 'sfield', 'field', 'upsert_df_data', 'upsert_deletor', 'get_row_versions', 'get_versions',
106
+ 'db_to_value', 'upsert_data', 'upsert_selector']
@@ -83,24 +83,27 @@ def upsert_deletor(values: SQLModel, session: Session):
83
83
  session.commit()
84
84
 
85
85
 
86
- def upsert_data(df: Union[pd.DataFrame], db_schema: SQLModelMetaclass, session: Session) -> None:
86
+ def upsert_df_data(df: Union[pd.DataFrame], db_schema: SQLModelMetaclass, session: Session) -> None:
87
87
  """
88
88
  Upsert the passed df into db_schema db.
89
89
  """
90
- upsert_dict_data([x.to_dict() for _, x in df.iterrows()], db_schema, session)
90
+ upsert_data([x.to_dict() for _, x in df.iterrows()], session, raw_db_schema=db_schema)
91
91
 
92
92
 
93
- def upsert_dict_data(data: list[dict], db_schema: SQLModelMetaclass, session: Session) -> None:
93
+ def upsert_data(data: list[dict | SQLModelMetaclass],
94
+ session: Session,
95
+ raw_db_schema: SQLModelMetaclass | None = None) -> None:
94
96
  """
95
97
  Upsert the passed list of dicts (corresponding to db_schema) into db_schema db.
96
98
  """
99
+ db_schema = raw_db_schema or data[0].__class__
97
100
  selector = partial(upsert_selector, db_schema=db_schema)
98
101
  updator = partial(upsert_updator, db_schema=db_schema)
99
102
  batches = [data[i:i + BATCH_SIZE] for i in range(0, len(data), BATCH_SIZE)]
100
103
 
101
104
  for batch in progressbar.progressbar(batches, redirect_stdout=False):
102
105
  for row in batch:
103
- new_object = db_schema(**row)
106
+ new_object = db_schema(**row) if isinstance(row, dict) else row
104
107
  if in_db := session.exec(selector(new_object)).first():
105
108
  session.exec(updator(new_object, in_db.id, session))
106
109
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ecodev-core
3
- Version: 0.0.44
3
+ Version: 0.0.45
4
4
  Summary: Low level sqlmodel/fastapi/pydantic building blocks
5
5
  License: MIT
6
6
  Author: Thomas Epelbaum
@@ -1,4 +1,4 @@
1
- ecodev_core/__init__.py,sha256=gSEDFqBQLI2tx2macOfnea0z1KdwntTpxbwtf0FiqjI,5785
1
+ ecodev_core/__init__.py,sha256=cIICQkHHfjmPIpLnpGlJ6GzGDvFT51bDeI8c1Kg3MH0,5781
2
2
  ecodev_core/app_activity.py,sha256=KBtI-35LBLPDppFB7xjxWthXQrY3Z_aGDnC-HrW8Ea0,4641
3
3
  ecodev_core/app_rights.py,sha256=RZPdDtydFqc_nFj96huKAc56BS0qS6ScKv4Kghqd6lc,726
4
4
  ecodev_core/app_user.py,sha256=r1bqA4H08x53XmxmjwyGKl_PFjYQazzBbVErdkztqeE,2947
@@ -11,7 +11,7 @@ ecodev_core/db_connection.py,sha256=bc5MujZ57f204wTsuNVdn1JdP-zBzkDJxHmdxBDTiNs,
11
11
  ecodev_core/db_filters.py,sha256=T_5JVF27UEu7sC6NOm7-W3_Y0GLfbWQO_EeTXcD2cv8,5041
12
12
  ecodev_core/db_insertion.py,sha256=RSCyAlUObbBlWJuMRX-YFY4VgtWqYLdwRqMWw--x95Y,3646
13
13
  ecodev_core/db_retrieval.py,sha256=IxyF3ZtKgACLiNFggK7boKggvMRKYDRD2IimxU4dap4,7345
14
- ecodev_core/db_upsertion.py,sha256=Gds1rgbrzFh0rkEY0gTwHLRnY-5izZvFmvZRekV47Zs,3936
14
+ ecodev_core/db_upsertion.py,sha256=HWx7yc1FAz6l6BQ_cPLUu5tIctO9F0WZj6zm1a06Fnw,4098
15
15
  ecodev_core/deployment.py,sha256=z8ACI00EtKknXOB8xyPwYIXTvPjIDOH9z9cBGEU0YrA,281
16
16
  ecodev_core/email_sender.py,sha256=XD7jAVXhGzvbiHqMhK9_aTEIS70Lw_CmPeAxRZGji-Y,1610
17
17
  ecodev_core/enum_utils.py,sha256=BkQ4YQ97tXBYmMcQiSIi0mbioD5CgVU79myg1BBAXuA,556
@@ -26,7 +26,7 @@ ecodev_core/safe_utils.py,sha256=Q8N15El1tSxZJJsy1i_1CCycuBN1_98QQoHmYJRcLIY,690
26
26
  ecodev_core/settings.py,sha256=ARAPkXxggVUsYqSQIAgCK8C2DKSMPia1CekULn428bA,1562
27
27
  ecodev_core/sqlmodel_utils.py,sha256=t57H3QPtKRy4ujic1clMK_2L4p0yjGJLZbDjHPZ8M94,453
28
28
  ecodev_core/version.py,sha256=BUMmO_dxwyTPGIbnbOTFIED4JMmOmN8khQzP2ea-Obg,4377
29
- ecodev_core-0.0.44.dist-info/LICENSE.md,sha256=8dqVJEbwXjPWjjRKjdLMym5k9Gi8hwtrHh84sti6KIs,1068
30
- ecodev_core-0.0.44.dist-info/METADATA,sha256=P-ssz6zvzY4RZmknnMlA2lr15jHnu2b0XBwuHtpdZLc,3509
31
- ecodev_core-0.0.44.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
- ecodev_core-0.0.44.dist-info/RECORD,,
29
+ ecodev_core-0.0.45.dist-info/LICENSE.md,sha256=8dqVJEbwXjPWjjRKjdLMym5k9Gi8hwtrHh84sti6KIs,1068
30
+ ecodev_core-0.0.45.dist-info/METADATA,sha256=SLR92pVQtSfoPqrU5Xp4hXcTEr4JjM-WCxsI-d9MvYg,3509
31
+ ecodev_core-0.0.45.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
+ ecodev_core-0.0.45.dist-info/RECORD,,