ecodev-core 0.0.44__tar.gz → 0.0.46__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 ecodev-core might be problematic. Click here for more details.
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/PKG-INFO +1 -1
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/__init__.py +3 -3
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/db_upsertion.py +22 -6
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/version.py +6 -6
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/pyproject.toml +1 -1
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/LICENSE.md +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/README.md +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/app_activity.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/app_rights.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/app_user.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/auth_configuration.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/authentication.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/backup.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/check_dependencies.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/custom_equal.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/db_connection.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/db_filters.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/db_insertion.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/db_retrieval.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/deployment.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/email_sender.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/enum_utils.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/es_connection.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/list_utils.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/logger.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/pandas_utils.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/permissions.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/pydantic_utils.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/read_write.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/safe_utils.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/settings.py +0 -0
- {ecodev_core-0.0.44 → ecodev_core-0.0.46}/ecodev_core/sqlmodel_utils.py +0 -0
|
@@ -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
|
|
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', '
|
|
106
|
-
'db_to_value', '
|
|
105
|
+
'sfield', 'field', 'upsert_df_data', 'upsert_deletor', 'get_row_versions', 'get_versions',
|
|
106
|
+
'db_to_value', 'upsert_data', 'upsert_selector']
|
|
@@ -22,6 +22,7 @@ from ecodev_core.version import Version
|
|
|
22
22
|
BATCH_SIZE = 5000
|
|
23
23
|
FILTER_ON = 'filter_on'
|
|
24
24
|
INFO = 'info'
|
|
25
|
+
SA_COLUMN_KWARGS = 'sa_column_kwargs'
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
def sfield(**kwargs):
|
|
@@ -29,14 +30,26 @@ def sfield(**kwargs):
|
|
|
29
30
|
Field constructor for columns not to be versioned. Those are the columns on which to select.
|
|
30
31
|
They morally are a sort of unique identifier of a row (like id but more business meaningful)
|
|
31
32
|
"""
|
|
32
|
-
|
|
33
|
+
sa_column_kwargs = _get_sa_column_kwargs(kwargs, sfield=True)
|
|
34
|
+
return Field(**kwargs, sa_column_kwargs=sa_column_kwargs)
|
|
33
35
|
|
|
34
36
|
|
|
35
37
|
def field(**kwargs):
|
|
36
38
|
"""
|
|
37
39
|
Field constructor for columns to be versioned.
|
|
38
40
|
"""
|
|
39
|
-
|
|
41
|
+
sa_column_kwargs = _get_sa_column_kwargs(kwargs, sfield=False)
|
|
42
|
+
return Field(**kwargs, sa_column_kwargs=sa_column_kwargs)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _get_sa_column_kwargs(kwargs, sfield: bool) -> dict:
|
|
46
|
+
"""
|
|
47
|
+
Combine existing sa_column_kwargs with the new field necessary for versioning
|
|
48
|
+
"""
|
|
49
|
+
if not (additional_vals := kwargs.get(SA_COLUMN_KWARGS)):
|
|
50
|
+
return {INFO: {FILTER_ON: sfield}}
|
|
51
|
+
kwargs.pop(SA_COLUMN_KWARGS)
|
|
52
|
+
return additional_vals | {INFO: {FILTER_ON: sfield}}
|
|
40
53
|
|
|
41
54
|
|
|
42
55
|
def upsert_selector(values: SQLModel, db_schema: SQLModelMetaclass) -> SelectOfScalar:
|
|
@@ -83,24 +96,27 @@ def upsert_deletor(values: SQLModel, session: Session):
|
|
|
83
96
|
session.commit()
|
|
84
97
|
|
|
85
98
|
|
|
86
|
-
def
|
|
99
|
+
def upsert_df_data(df: Union[pd.DataFrame], db_schema: SQLModelMetaclass, session: Session) -> None:
|
|
87
100
|
"""
|
|
88
101
|
Upsert the passed df into db_schema db.
|
|
89
102
|
"""
|
|
90
|
-
|
|
103
|
+
upsert_data([x.to_dict() for _, x in df.iterrows()], session, raw_db_schema=db_schema)
|
|
91
104
|
|
|
92
105
|
|
|
93
|
-
def
|
|
106
|
+
def upsert_data(data: list[dict | SQLModelMetaclass],
|
|
107
|
+
session: Session,
|
|
108
|
+
raw_db_schema: SQLModelMetaclass | None = None) -> None:
|
|
94
109
|
"""
|
|
95
110
|
Upsert the passed list of dicts (corresponding to db_schema) into db_schema db.
|
|
96
111
|
"""
|
|
112
|
+
db_schema = raw_db_schema or data[0].__class__
|
|
97
113
|
selector = partial(upsert_selector, db_schema=db_schema)
|
|
98
114
|
updator = partial(upsert_updator, db_schema=db_schema)
|
|
99
115
|
batches = [data[i:i + BATCH_SIZE] for i in range(0, len(data), BATCH_SIZE)]
|
|
100
116
|
|
|
101
117
|
for batch in progressbar.progressbar(batches, redirect_stdout=False):
|
|
102
118
|
for row in batch:
|
|
103
|
-
new_object = db_schema(**row)
|
|
119
|
+
new_object = db_schema(**row) if isinstance(row, dict) else row
|
|
104
120
|
if in_db := session.exec(selector(new_object)).first():
|
|
105
121
|
session.exec(updator(new_object, in_db.id, session))
|
|
106
122
|
else:
|
|
@@ -38,7 +38,7 @@ class Version(SQLModel, table=True): # type: ignore
|
|
|
38
38
|
Attributes are:
|
|
39
39
|
- table: the table to version
|
|
40
40
|
- column: the column of table to version
|
|
41
|
-
- row_id: the
|
|
41
|
+
- row_id: the row id of the column of table to version
|
|
42
42
|
- col_type: the column type
|
|
43
43
|
- value: the value to store (previous row/column/table version)
|
|
44
44
|
"""
|
|
@@ -97,15 +97,15 @@ def _col_type_to_db(col_type: type | EnumType) -> ColType:
|
|
|
97
97
|
"""
|
|
98
98
|
Forge ColType out of passed col_type
|
|
99
99
|
"""
|
|
100
|
-
if col_type
|
|
100
|
+
if issubclass(int, col_type):
|
|
101
101
|
return ColType.INT
|
|
102
|
-
if col_type
|
|
102
|
+
if issubclass(bool, col_type):
|
|
103
103
|
return ColType.BOOL
|
|
104
|
-
if col_type
|
|
104
|
+
if issubclass(float, col_type):
|
|
105
105
|
return ColType.FLOAT
|
|
106
|
-
if col_type
|
|
106
|
+
if issubclass(str, col_type):
|
|
107
107
|
return ColType.STR
|
|
108
|
-
if col_type
|
|
108
|
+
if issubclass(datetime, col_type):
|
|
109
109
|
return ColType.DATE
|
|
110
110
|
return ColType.ENUM
|
|
111
111
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|