statikk 0.1.5__py3-none-any.whl → 0.1.7__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.
statikk/engine.py CHANGED
@@ -232,9 +232,13 @@ class Table:
232
232
 
233
233
  Returns the enriched database model instance.
234
234
  """
235
+
235
236
  with self.batch_write() as batch:
236
237
  for item in model.split_to_simple_objects():
237
- batch.put(item)
238
+ if item._should_delete:
239
+ batch.delete(item)
240
+ else:
241
+ batch.put(item)
238
242
 
239
243
  def update_item(
240
244
  self,
statikk/models.py CHANGED
@@ -67,16 +67,18 @@ class TrackingMixin:
67
67
 
68
68
  def _recursive_hash(self) -> int:
69
69
  """
70
- Compute a hash value for the model, ignoring nested DatabaseModel instances.
70
+ Compute a hash value for the model, ignoring specified fields and nested DatabaseModel instances.
71
71
 
72
- This ensures that changes to child models don't affect the parent's hash.
72
+ This ensures that changes to ignored fields or child models don't affect the parent's hash.
73
73
 
74
74
  Returns:
75
- A hash value representing the model's non-model fields.
75
+ A hash value representing the model's non-ignored fields.
76
76
  """
77
77
  if not self.should_track:
78
78
  return 0
79
79
 
80
+ ignored_fields = self.ignore_tracking_fields()
81
+
80
82
  values = []
81
83
  for field_name in self.model_fields:
82
84
  if not hasattr(self, field_name):
@@ -85,6 +87,9 @@ class TrackingMixin:
85
87
  if field_name.startswith("_"):
86
88
  continue
87
89
 
90
+ if field_name in ignored_fields:
91
+ continue
92
+
88
93
  value = getattr(self, field_name)
89
94
 
90
95
  if hasattr(value, "__class__") and issubclass(value.__class__, DatabaseModel):
@@ -141,11 +146,23 @@ class TrackingMixin:
141
146
 
142
147
  return True
143
148
 
149
+ def ignore_tracking_fields(self) -> set:
150
+ """
151
+ Override this method to specify fields to ignore when tracking changes.
152
+
153
+ Returns:
154
+ A set specifying fields to ignore.
155
+ Example:
156
+ {"field1", "field2"}
157
+ """
158
+ return {}
159
+
144
160
 
145
161
  class DatabaseModel(BaseModel, TrackingMixin, extra=Extra.allow):
146
162
  id: str = Field(default_factory=lambda: str(uuid4()))
147
163
  _parent: Optional[DatabaseModel] = None
148
164
  _model_types_in_hierarchy: dict[str, Type[DatabaseModel]] = {}
165
+ _should_delete: bool = False
149
166
 
150
167
  @classmethod
151
168
  def type(cls) -> str:
@@ -240,6 +257,9 @@ class DatabaseModel(BaseModel, TrackingMixin, extra=Extra.allow):
240
257
  return self._parent.should_write_to_database()
241
258
  return True
242
259
 
260
+ def mark_for_delete(self):
261
+ self._should_delete = True
262
+
243
263
  @classmethod
244
264
  def scan(
245
265
  cls,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: statikk
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: statikk is a single table application (STA) library for DynamoDb.
5
5
  Home-page: https://github.com/terinia/statikk
6
6
  Author: Balint Biro
@@ -0,0 +1,12 @@
1
+ statikk/__init__.py,sha256=pH5i4Fj1tbXLqLtTVIdoojiplZssQn0nnud8-HXodRE,577
2
+ statikk/conditions.py,sha256=63FYMR-UUaE-ZJEb_8CU721CQTwhajq39-BbokmKeMA,2166
3
+ statikk/engine.py,sha256=_iUJYyKNypqQeg6f4MC45XWhOrwsYRsI8FZe0Hs3fDA,31067
4
+ statikk/expressions.py,sha256=mF6Hmj3Kmj6KKXTymeTHSepVA7rhiSINpFgSAPeBTRY,12210
5
+ statikk/fields.py,sha256=LkMP5NnX7WS0HSLxI3Q-dMOrfaJ0SD7SayZxJU5Acgg,86
6
+ statikk/models.py,sha256=uGCfpmoagz98BlTWiyj8NFvd7PTcsj1XV2edTumxAqY,13862
7
+ statikk/typing.py,sha256=qfpegORcdODuILK3gvuD4SdcZA1a7Myn0yvscOLPHOM,68
8
+ statikk-0.1.7.dist-info/LICENSE.txt,sha256=uSH_2Hpb2Bigy5_HhBliN2fZbBU64G3ERM5zzhKPUEE,1078
9
+ statikk-0.1.7.dist-info/METADATA,sha256=YiDH3MeMZuJypLtkjGb-prE-Aqe15kbKBDT9cAyBRmM,3160
10
+ statikk-0.1.7.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
11
+ statikk-0.1.7.dist-info/top_level.txt,sha256=etKmBbjzIlLpSefXoiOfhWGEgvqUEALaFwCjFDBD9YI,8
12
+ statikk-0.1.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.9.1)
2
+ Generator: setuptools (76.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,12 +0,0 @@
1
- statikk/__init__.py,sha256=pH5i4Fj1tbXLqLtTVIdoojiplZssQn0nnud8-HXodRE,577
2
- statikk/conditions.py,sha256=63FYMR-UUaE-ZJEb_8CU721CQTwhajq39-BbokmKeMA,2166
3
- statikk/engine.py,sha256=U2STo-d8Rf6jiPtIdVgGdZ11G6xYjn-yehFdeCb7ZO8,30961
4
- statikk/expressions.py,sha256=mF6Hmj3Kmj6KKXTymeTHSepVA7rhiSINpFgSAPeBTRY,12210
5
- statikk/fields.py,sha256=LkMP5NnX7WS0HSLxI3Q-dMOrfaJ0SD7SayZxJU5Acgg,86
6
- statikk/models.py,sha256=r8vjVvm1wgPTeGuuiUW0ydfppytZ3PJxYDEOZudmCTU,13307
7
- statikk/typing.py,sha256=qfpegORcdODuILK3gvuD4SdcZA1a7Myn0yvscOLPHOM,68
8
- statikk-0.1.5.dist-info/LICENSE.txt,sha256=uSH_2Hpb2Bigy5_HhBliN2fZbBU64G3ERM5zzhKPUEE,1078
9
- statikk-0.1.5.dist-info/METADATA,sha256=zrecdBN5rNUA7xD-NpGEoQEtG5Q976gHLONd6wxZRYg,3160
10
- statikk-0.1.5.dist-info/WHEEL,sha256=EaM1zKIUYa7rQnxGiOCGhzJABRwy4WO57rWMR3_tj4I,91
11
- statikk-0.1.5.dist-info/top_level.txt,sha256=etKmBbjzIlLpSefXoiOfhWGEgvqUEALaFwCjFDBD9YI,8
12
- statikk-0.1.5.dist-info/RECORD,,