statikk 0.1.9__tar.gz → 0.1.10__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.
Files changed (43) hide show
  1. {statikk-0.1.9 → statikk-0.1.10}/PKG-INFO +1 -1
  2. {statikk-0.1.9 → statikk-0.1.10}/src/statikk/engine.py +10 -5
  3. {statikk-0.1.9 → statikk-0.1.10}/src/statikk/models.py +3 -0
  4. {statikk-0.1.9 → statikk-0.1.10}/src/statikk.egg-info/PKG-INFO +1 -1
  5. {statikk-0.1.9 → statikk-0.1.10}/tests/test_engine.py +29 -0
  6. {statikk-0.1.9 → statikk-0.1.10}/tests/test_models.py +1 -1
  7. {statikk-0.1.9 → statikk-0.1.10}/.coveragerc +0 -0
  8. {statikk-0.1.9 → statikk-0.1.10}/.gitignore +0 -0
  9. {statikk-0.1.9 → statikk-0.1.10}/.readthedocs.yml +0 -0
  10. {statikk-0.1.9 → statikk-0.1.10}/AUTHORS.rst +0 -0
  11. {statikk-0.1.9 → statikk-0.1.10}/CHANGELOG.rst +0 -0
  12. {statikk-0.1.9 → statikk-0.1.10}/CONTRIBUTING.rst +0 -0
  13. {statikk-0.1.9 → statikk-0.1.10}/LICENSE.txt +0 -0
  14. {statikk-0.1.9 → statikk-0.1.10}/README.rst +0 -0
  15. {statikk-0.1.9 → statikk-0.1.10}/assets/favicon.png +0 -0
  16. {statikk-0.1.9 → statikk-0.1.10}/assets/logo.png +0 -0
  17. {statikk-0.1.9 → statikk-0.1.10}/docs/Makefile +0 -0
  18. {statikk-0.1.9 → statikk-0.1.10}/docs/_static/.gitignore +0 -0
  19. {statikk-0.1.9 → statikk-0.1.10}/docs/authors.rst +0 -0
  20. {statikk-0.1.9 → statikk-0.1.10}/docs/changelog.rst +0 -0
  21. {statikk-0.1.9 → statikk-0.1.10}/docs/conf.py +0 -0
  22. {statikk-0.1.9 → statikk-0.1.10}/docs/contributing.rst +0 -0
  23. {statikk-0.1.9 → statikk-0.1.10}/docs/index.rst +0 -0
  24. {statikk-0.1.9 → statikk-0.1.10}/docs/license.rst +0 -0
  25. {statikk-0.1.9 → statikk-0.1.10}/docs/readme.rst +0 -0
  26. {statikk-0.1.9 → statikk-0.1.10}/docs/requirements.txt +0 -0
  27. {statikk-0.1.9 → statikk-0.1.10}/docs/usage.rst +0 -0
  28. {statikk-0.1.9 → statikk-0.1.10}/pyproject.toml +0 -0
  29. {statikk-0.1.9 → statikk-0.1.10}/setup.cfg +0 -0
  30. {statikk-0.1.9 → statikk-0.1.10}/setup.py +0 -0
  31. {statikk-0.1.9 → statikk-0.1.10}/src/statikk/__init__.py +0 -0
  32. {statikk-0.1.9 → statikk-0.1.10}/src/statikk/conditions.py +0 -0
  33. {statikk-0.1.9 → statikk-0.1.10}/src/statikk/expressions.py +0 -0
  34. {statikk-0.1.9 → statikk-0.1.10}/src/statikk/fields.py +0 -0
  35. {statikk-0.1.9 → statikk-0.1.10}/src/statikk/typing.py +0 -0
  36. {statikk-0.1.9 → statikk-0.1.10}/src/statikk.egg-info/SOURCES.txt +0 -0
  37. {statikk-0.1.9 → statikk-0.1.10}/src/statikk.egg-info/dependency_links.txt +0 -0
  38. {statikk-0.1.9 → statikk-0.1.10}/src/statikk.egg-info/not-zip-safe +0 -0
  39. {statikk-0.1.9 → statikk-0.1.10}/src/statikk.egg-info/requires.txt +0 -0
  40. {statikk-0.1.9 → statikk-0.1.10}/src/statikk.egg-info/top_level.txt +0 -0
  41. {statikk-0.1.9 → statikk-0.1.10}/tests/conftest.py +0 -0
  42. {statikk-0.1.9 → statikk-0.1.10}/tests/test_expressions.py +0 -0
  43. {statikk-0.1.9 → statikk-0.1.10}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: statikk
3
- Version: 0.1.9
3
+ Version: 0.1.10
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
@@ -307,15 +307,20 @@ class Table:
307
307
  subtree_copy._parent = new_parent
308
308
  for node in subtree_copy.dfs_traverse_hierarchy():
309
309
  for idx in self.indexes:
310
- new_index_values = self._compose_index_values(node, idx)
311
- new_sort_key_value = new_index_values[idx.sort_key.name]
312
- setattr(node, idx.sort_key.name, new_sort_key_value)
313
- new_hash_key_value = new_index_values[idx.hash_key.name]
314
- setattr(node, idx.hash_key.name, new_hash_key_value)
310
+ self.build_model_indexes(node)
315
311
  setattr(node, FIELD_STATIKK_PARENT_ID, new_parent.id)
316
312
 
317
313
  return subtree_copy
318
314
 
315
+ def build_model_indexes(self, model: T) -> T:
316
+ for idx in self.indexes:
317
+ new_index_values = self._compose_index_values(model, idx)
318
+ new_sort_key_value = new_index_values[idx.sort_key.name]
319
+ setattr(model, idx.sort_key.name, new_sort_key_value)
320
+ new_hash_key_value = new_index_values[idx.hash_key.name]
321
+ setattr(model, idx.hash_key.name, new_hash_key_value)
322
+ return model
323
+
319
324
  def batch_write(self):
320
325
  """
321
326
  Returns a context manager for batch writing items to the database. This method handles all the buffering of the
@@ -217,6 +217,9 @@ class DatabaseModel(BaseModel, TrackingMixin, extra=Extra.allow):
217
217
  current = current._parent
218
218
  return False
219
219
 
220
+ def build_model_indexes(self) -> T:
221
+ return self._table.build_model_indexes(self)
222
+
220
223
  @classmethod
221
224
  def query(
222
225
  cls: Type[T],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: statikk
3
- Version: 0.1.9
3
+ Version: 0.1.10
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
@@ -951,3 +951,32 @@ def test_update_parent():
951
951
  hierarchy.save()
952
952
  hierarchy = Model.query_hierarchy(hash_key=Equals("model-1"))
953
953
  assert len(hierarchy.nested) == 0
954
+
955
+
956
+ def test_rebuild_model_indexes():
957
+ class MyDatabaseModel(DatabaseModel):
958
+ foo: str = "foo"
959
+ bar: str = "bar"
960
+
961
+ @classmethod
962
+ def index_definitions(cls) -> dict[str, IndexFieldConfig]:
963
+ return {"main-index": IndexFieldConfig(pk_fields=["foo"], sk_fields=["bar"])}
964
+
965
+ mock_dynamodb().start()
966
+ table = Table(
967
+ name="my-dynamodb-table",
968
+ key_schema=KeySchema(hash_key="id"),
969
+ indexes=[
970
+ GSI(
971
+ name="main-index",
972
+ hash_key=Key(name="gsi_pk"),
973
+ sort_key=Key(name="gsi_sk"),
974
+ )
975
+ ],
976
+ models=[MyDatabaseModel],
977
+ )
978
+ _create_dynamodb_table(table)
979
+ my_database_model = MyDatabaseModel(foo="foo", bar="bar")
980
+ my_database_model.build_model_indexes()
981
+ assert my_database_model.gsi_pk == "foo"
982
+ assert my_database_model.gsi_sk == "MyDatabaseModel|bar"
@@ -1,5 +1,5 @@
1
1
  from pydantic import BaseModel
2
- from statikk.models import DatabaseModel
2
+ from statikk.models import DatabaseModel, IndexFieldConfig
3
3
 
4
4
 
5
5
  class SimpleObject(BaseModel):
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