industrial-model 0.1.17__tar.gz → 0.1.19__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 (44) hide show
  1. {industrial_model-0.1.17 → industrial_model-0.1.19}/PKG-INFO +17 -1
  2. {industrial_model-0.1.17 → industrial_model-0.1.19}/README.md +16 -0
  3. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/__init__.py +8 -3
  4. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/query_result_mapper.py +1 -1
  5. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/engines/async_engine.py +3 -0
  6. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/engines/engine.py +5 -0
  7. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/models/entities.py +3 -0
  8. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/models/schemas.py +1 -1
  9. {industrial_model-0.1.17 → industrial_model-0.1.19}/pyproject.toml +1 -1
  10. {industrial_model-0.1.17 → industrial_model-0.1.19}/uv.lock +1 -1
  11. {industrial_model-0.1.17 → industrial_model-0.1.19}/.gitignore +0 -0
  12. {industrial_model-0.1.17 → industrial_model-0.1.19}/.python-version +0 -0
  13. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/__init__.py +0 -0
  14. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/aggregation_mapper.py +0 -0
  15. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/filter_mapper.py +0 -0
  16. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/models.py +0 -0
  17. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/optimizer.py +0 -0
  18. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/query_mapper.py +0 -0
  19. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/sort_mapper.py +0 -0
  20. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/upsert_mapper.py +0 -0
  21. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/utils.py +0 -0
  22. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/cognite_adapters/view_mapper.py +0 -0
  23. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/config.py +0 -0
  24. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/constants.py +0 -0
  25. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/engines/__init__.py +0 -0
  26. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/models/__init__.py +0 -0
  27. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/models/base.py +0 -0
  28. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/py.typed +0 -0
  29. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/queries/__init__.py +0 -0
  30. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/queries/models.py +0 -0
  31. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/queries/params.py +0 -0
  32. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/statements/__init__.py +0 -0
  33. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/statements/expressions.py +0 -0
  34. {industrial_model-0.1.17 → industrial_model-0.1.19}/industrial_model/utils.py +0 -0
  35. {industrial_model-0.1.17 → industrial_model-0.1.19}/scripts/build.sh +0 -0
  36. {industrial_model-0.1.17 → industrial_model-0.1.19}/scripts/format.sh +0 -0
  37. {industrial_model-0.1.17 → industrial_model-0.1.19}/scripts/lint.sh +0 -0
  38. {industrial_model-0.1.17 → industrial_model-0.1.19}/tests/__init__.py +0 -0
  39. {industrial_model-0.1.17 → industrial_model-0.1.19}/tests/cognite-sdk-config.yaml +0 -0
  40. {industrial_model-0.1.17 → industrial_model-0.1.19}/tests/hubs.py +0 -0
  41. {industrial_model-0.1.17 → industrial_model-0.1.19}/tests/models.py +0 -0
  42. {industrial_model-0.1.17 → industrial_model-0.1.19}/tests/test_upsert_mapper.py +0 -0
  43. {industrial_model-0.1.17 → industrial_model-0.1.19}/tests/tests_adapter.py +0 -0
  44. {industrial_model-0.1.17 → industrial_model-0.1.19}/tests/tests_aggregate.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: industrial-model
3
- Version: 0.1.17
3
+ Version: 0.1.19
4
4
  Summary: Industrial Model ORM
5
5
  Author-email: Lucas Alves <lucasrosaalves@gmail.com>
6
6
  Classifier: Programming Language :: Python
@@ -229,6 +229,22 @@ class AggregateByNamePerson(AggregatedViewInstance):
229
229
  aggregate_result = engine.aggregate(aggregate(AggregateByNamePerson, "count"))
230
230
 
231
231
 
232
+
233
+ # 9. Deletion
234
+
235
+ class Entity(ViewInstance):
236
+ view_config = ViewInstanceConfig(
237
+ view_external_id="Person"
238
+ )
239
+ name: str
240
+
241
+
242
+ statement = select(Entity).where(Entity.external_id == "Lucas")
243
+ person = engine.query_all_pages(statement)[0]
244
+
245
+
246
+ engine.delete([person])
247
+
232
248
  ```
233
249
 
234
250
  ---
@@ -209,6 +209,22 @@ class AggregateByNamePerson(AggregatedViewInstance):
209
209
  aggregate_result = engine.aggregate(aggregate(AggregateByNamePerson, "count"))
210
210
 
211
211
 
212
+
213
+ # 9. Deletion
214
+
215
+ class Entity(ViewInstance):
216
+ view_config = ViewInstanceConfig(
217
+ view_external_id="Person"
218
+ )
219
+ name: str
220
+
221
+
222
+ statement = select(Entity).where(Entity.external_id == "Lucas")
223
+ person = engine.query_all_pages(statement)[0]
224
+
225
+
226
+ engine.delete([person])
227
+
212
228
  ```
213
229
 
214
230
  ---
@@ -111,7 +111,7 @@ class CogniteAdapter:
111
111
  operation = self._upsert_mapper.map(entries)
112
112
 
113
113
  for node_chunk in operation.chunk_nodes():
114
- logger.info(
114
+ logger.debug(
115
115
  f"Upserting {len(node_chunk)} nodes (replace={replace})"
116
116
  )
117
117
  self._cognite_client.data_modeling.instances.apply(
@@ -120,7 +120,7 @@ class CogniteAdapter:
120
120
  )
121
121
 
122
122
  for edge_chunk in operation.chunk_edges():
123
- logger.info(
123
+ logger.debug(
124
124
  f"Upserting {len(edge_chunk)} edges (replace={replace})"
125
125
  )
126
126
  self._cognite_client.data_modeling.instances.apply(
@@ -129,11 +129,16 @@ class CogniteAdapter:
129
129
  )
130
130
 
131
131
  for edges_to_remove_chunk in operation.chunk_edges_to_delete():
132
- logger.info(f"Deleting {len(edges_to_remove_chunk)} edges")
132
+ logger.debug(f"Deleting {len(edges_to_remove_chunk)} edges")
133
133
  self._cognite_client.data_modeling.instances.delete(
134
134
  edges=[item.as_tuple() for item in edges_to_remove_chunk],
135
135
  )
136
136
 
137
+ def delete(self, nodes: list[TViewInstance]) -> None:
138
+ self._cognite_client.data_modeling.instances.delete(
139
+ nodes=[item.as_tuple() for item in nodes],
140
+ )
141
+
137
142
  def _query_dependencies_pages(
138
143
  self,
139
144
  cognite_query: CogniteQuery,
@@ -1,6 +1,6 @@
1
1
  from collections import defaultdict
2
2
  from enum import StrEnum
3
- from typing import Any, Literal, TypedDict
3
+ from typing import Any, TypedDict
4
4
 
5
5
  from cognite.client.data_classes.data_modeling import (
6
6
  Edge,
@@ -47,3 +47,6 @@ class AsyncEngine:
47
47
  self, entries: list[TWritableViewInstance], replace: bool = False
48
48
  ) -> None:
49
49
  return await run_async(self._engine.upsert, entries, replace)
50
+
51
+ async def delete_async(self, nodes: list[TViewInstance]) -> None:
52
+ return await run_async(self._engine.delete, nodes)
@@ -63,6 +63,11 @@ class Engine:
63
63
 
64
64
  return self._cognite_adapter.upsert(entries, replace)
65
65
 
66
+ def delete(self, nodes: list[TViewInstance]) -> None:
67
+ self._cognite_adapter.delete(
68
+ nodes,
69
+ )
70
+
66
71
  def _validate_data(
67
72
  self,
68
73
  entity: type[TViewInstance],
@@ -101,5 +101,8 @@ class PaginatedResult(RootModel, Generic[TViewInstance]):
101
101
  has_next_page: bool
102
102
  next_cursor: str | None
103
103
 
104
+ def first_or_default(self) -> TViewInstance | None:
105
+ return self.data[0] if self.data else None
106
+
104
107
 
105
108
  ValidationMode = Literal["raiseOnError", "ignoreOnError"]
@@ -99,7 +99,7 @@ def _get_field_type(
99
99
  entries: list[type[BaseModel] | None] = []
100
100
  for arg in get_args(type_hint):
101
101
  if _type_is_list_or_union(arg):
102
- return _get_field_type(arg, visited_count)
102
+ return _get_field_type(arg, parent_type, visited_count)
103
103
  entries.append(_cast_base_model(arg))
104
104
 
105
105
  return _get_field_relations(entries, parent_type, visited_count)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "industrial-model"
3
- version = "0.1.17"
3
+ version = "0.1.19"
4
4
  description = "Industrial Model ORM"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -215,7 +215,7 @@ wheels = [
215
215
 
216
216
  [[package]]
217
217
  name = "industrial-model"
218
- version = "0.1.17"
218
+ version = "0.1.19"
219
219
  source = { editable = "." }
220
220
  dependencies = [
221
221
  { name = "anyio" },