ecodev-core 0.0.45__tar.gz → 0.0.47__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.45 → ecodev_core-0.0.47}/PKG-INFO +1 -1
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/db_upsertion.py +26 -3
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/version.py +6 -6
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/pyproject.toml +1 -1
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/LICENSE.md +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/README.md +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/__init__.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/app_activity.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/app_rights.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/app_user.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/auth_configuration.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/authentication.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/backup.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/check_dependencies.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/custom_equal.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/db_connection.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/db_filters.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/db_insertion.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/db_retrieval.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/deployment.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/email_sender.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/enum_utils.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/es_connection.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/list_utils.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/logger.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/pandas_utils.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/permissions.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/pydantic_utils.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/read_write.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/safe_utils.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/settings.py +0 -0
- {ecodev_core-0.0.45 → ecodev_core-0.0.47}/ecodev_core/sqlmodel_utils.py +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Module handling CRUD and version operations
|
|
3
3
|
"""
|
|
4
|
+
from datetime import datetime
|
|
4
5
|
from functools import partial
|
|
6
|
+
from typing import Any
|
|
5
7
|
from typing import Union
|
|
6
8
|
|
|
7
9
|
import pandas as pd
|
|
@@ -22,6 +24,7 @@ from ecodev_core.version import Version
|
|
|
22
24
|
BATCH_SIZE = 5000
|
|
23
25
|
FILTER_ON = 'filter_on'
|
|
24
26
|
INFO = 'info'
|
|
27
|
+
SA_COLUMN_KWARGS = 'sa_column_kwargs'
|
|
25
28
|
|
|
26
29
|
|
|
27
30
|
def sfield(**kwargs):
|
|
@@ -29,14 +32,26 @@ def sfield(**kwargs):
|
|
|
29
32
|
Field constructor for columns not to be versioned. Those are the columns on which to select.
|
|
30
33
|
They morally are a sort of unique identifier of a row (like id but more business meaningful)
|
|
31
34
|
"""
|
|
32
|
-
|
|
35
|
+
sa_column_kwargs = _get_sa_column_kwargs(kwargs, sfield=True)
|
|
36
|
+
return Field(**kwargs, sa_column_kwargs=sa_column_kwargs)
|
|
33
37
|
|
|
34
38
|
|
|
35
39
|
def field(**kwargs):
|
|
36
40
|
"""
|
|
37
41
|
Field constructor for columns to be versioned.
|
|
38
42
|
"""
|
|
39
|
-
|
|
43
|
+
sa_column_kwargs = _get_sa_column_kwargs(kwargs, sfield=False)
|
|
44
|
+
return Field(**kwargs, sa_column_kwargs=sa_column_kwargs)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _get_sa_column_kwargs(kwargs, sfield: bool) -> dict:
|
|
48
|
+
"""
|
|
49
|
+
Combine existing sa_column_kwargs with the new field necessary for versioning
|
|
50
|
+
"""
|
|
51
|
+
if not (additional_vals := kwargs.get(SA_COLUMN_KWARGS)):
|
|
52
|
+
return {INFO: {FILTER_ON: sfield}}
|
|
53
|
+
kwargs.pop(SA_COLUMN_KWARGS)
|
|
54
|
+
return additional_vals | {INFO: {FILTER_ON: sfield}}
|
|
40
55
|
|
|
41
56
|
|
|
42
57
|
def upsert_selector(values: SQLModel, db_schema: SQLModelMetaclass) -> SelectOfScalar:
|
|
@@ -65,12 +80,20 @@ def upsert_updator(values: SQLModel,
|
|
|
65
80
|
col_types = {x: y.annotation for x, y in db_schema.__fields__.items()}
|
|
66
81
|
table = db_schema.__tablename__
|
|
67
82
|
|
|
68
|
-
for col, val in {k: v for k, v in db.items() if k in to_update and
|
|
83
|
+
for col, val in {k: v for k, v in db.items() if k in to_update and _value_comparator(
|
|
84
|
+
v, to_update[k])}.items():
|
|
69
85
|
session.add(Version.from_table_row(table, col, row_id, col_types[col], val))
|
|
70
86
|
|
|
71
87
|
return update(db_schema).where(db_schema.id == row_id).values(**to_update)
|
|
72
88
|
|
|
73
89
|
|
|
90
|
+
def _value_comparator(v: Any, to_update: Any) -> bool:
|
|
91
|
+
"""
|
|
92
|
+
Performs a comparison between the value in db and the value to be upserted
|
|
93
|
+
"""
|
|
94
|
+
return v.date() != to_update.date() if isinstance(v, datetime) else v != to_update
|
|
95
|
+
|
|
96
|
+
|
|
74
97
|
def upsert_deletor(values: SQLModel, session: Session):
|
|
75
98
|
"""
|
|
76
99
|
Delete row in db corresponding to the passed values, selecting on columns not to be versioned.
|
|
@@ -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
|
|
File without changes
|