statikk 0.0.10__py3-none-any.whl → 0.0.12__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 +27 -12
- {statikk-0.0.10.dist-info → statikk-0.0.12.dist-info}/METADATA +4 -3
- statikk-0.0.12.dist-info/RECORD +10 -0
- {statikk-0.0.10.dist-info → statikk-0.0.12.dist-info}/WHEEL +1 -1
- statikk-0.0.10.dist-info/RECORD +0 -10
- {statikk-0.0.10.dist-info → statikk-0.0.12.dist-info}/LICENSE.txt +0 -0
- {statikk-0.0.10.dist-info → statikk-0.0.12.dist-info}/top_level.txt +0 -0
statikk/engine.py
CHANGED
@@ -19,6 +19,10 @@ from statikk.models import (
|
|
19
19
|
KeySchema,
|
20
20
|
)
|
21
21
|
|
22
|
+
from aws_xray_sdk.core import xray_recorder
|
23
|
+
from aws_xray_sdk.core import patch_all
|
24
|
+
|
25
|
+
patch_all()
|
22
26
|
|
23
27
|
class InvalidIndexNameError(Exception):
|
24
28
|
pass
|
@@ -54,19 +58,30 @@ class Table:
|
|
54
58
|
model.set_table_ref(self)
|
55
59
|
if "type" not in model.model_fields:
|
56
60
|
model.model_fields["type"] = FieldInfo(annotation=str, default=model.model_type(), required=False)
|
61
|
+
self._client = None
|
62
|
+
self._dynamodb_table = None
|
57
63
|
|
58
64
|
def _dynamodb_client(self):
|
59
|
-
|
65
|
+
if self._client:
|
66
|
+
return self._client
|
67
|
+
|
68
|
+
self._client = boto3.client(
|
60
69
|
"dynamodb",
|
61
70
|
config=Config(region_name=os.environ.get("AWS_DEFAULT_REGION", "eu-west-1")),
|
62
71
|
)
|
63
72
|
|
73
|
+
return self._client
|
74
|
+
|
64
75
|
def _get_dynamodb_table(self):
|
76
|
+
if self._dynamodb_table:
|
77
|
+
return self._dynamodb_table
|
78
|
+
|
65
79
|
dynamodb = boto3.resource(
|
66
80
|
"dynamodb",
|
67
81
|
config=Config(region_name=os.environ.get("AWS_DEFAULT_REGION", "eu-west-1")),
|
68
82
|
)
|
69
|
-
|
83
|
+
self._dynamodb_table = dynamodb.Table(self.name)
|
84
|
+
return self._dynamodb_table
|
70
85
|
|
71
86
|
def _to_dynamodb_type(self, type: Any):
|
72
87
|
if type is str:
|
@@ -149,14 +164,6 @@ class Table:
|
|
149
164
|
"""Deletes the DynamoDB table."""
|
150
165
|
self._dynamodb_client().delete_table(TableName=self.name)
|
151
166
|
|
152
|
-
def delete_item(self, id: str):
|
153
|
-
"""
|
154
|
-
Deletes an item from the database by id, using the partition key of the table.
|
155
|
-
:param id: The id of the item to delete.
|
156
|
-
"""
|
157
|
-
key = {self.key_schema.hash_key: id}
|
158
|
-
self._get_dynamodb_table().delete_item(Key=key)
|
159
|
-
|
160
167
|
def get_item(
|
161
168
|
self,
|
162
169
|
id: str,
|
@@ -181,6 +188,14 @@ class Table:
|
|
181
188
|
data[key] = self._deserialize_value(value, model_class.model_fields[key])
|
182
189
|
return model_class(**data)
|
183
190
|
|
191
|
+
def delete_item(self, id: str):
|
192
|
+
"""
|
193
|
+
Deletes an item from the database by id, using the partition key of the table.
|
194
|
+
:param id: The id of the item to delete.
|
195
|
+
"""
|
196
|
+
key = {self.key_schema.hash_key: id}
|
197
|
+
self._get_dynamodb_table().delete_item(Key=key)
|
198
|
+
|
184
199
|
def put_item(self, model: DatabaseModel) -> DatabaseModel:
|
185
200
|
"""
|
186
201
|
Puts an item into the database.
|
@@ -374,7 +389,7 @@ class Table:
|
|
374
389
|
else:
|
375
390
|
results.extend(
|
376
391
|
[
|
377
|
-
|
392
|
+
self._deserialize_item(self._convert_dynamodb_to_python(item), model_class)
|
378
393
|
for item in response["Responses"][self.name]
|
379
394
|
]
|
380
395
|
)
|
@@ -410,7 +425,7 @@ class Table:
|
|
410
425
|
return model_class(**item)
|
411
426
|
|
412
427
|
def _deserialize_value(self, value: Any, annotation: Any):
|
413
|
-
if annotation is datetime or "datetime" in str(annotation):
|
428
|
+
if annotation is datetime or "datetime" in str(annotation) and value is not None:
|
414
429
|
return datetime.fromtimestamp(int(value))
|
415
430
|
if annotation is float:
|
416
431
|
return float(value)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: statikk
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.12
|
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
|
@@ -13,14 +13,15 @@ Classifier: Programming Language :: Python
|
|
13
13
|
Requires-Python: >=3.8
|
14
14
|
Description-Content-Type: text/x-rst; charset=UTF-8
|
15
15
|
License-File: LICENSE.txt
|
16
|
-
Requires-Dist: pydantic ==2.
|
16
|
+
Requires-Dist: pydantic ==2.7.4
|
17
17
|
Requires-Dist: boto3 ==1.28.43
|
18
|
+
Requires-Dist: aws-xray-sdk ==2.14.0
|
18
19
|
Requires-Dist: importlib-metadata ; python_version < "3.8"
|
19
20
|
Provides-Extra: testing
|
20
21
|
Requires-Dist: setuptools ; extra == 'testing'
|
21
22
|
Requires-Dist: pytest ; extra == 'testing'
|
22
23
|
Requires-Dist: pytest-cov ; extra == 'testing'
|
23
|
-
Requires-Dist: moto[dynamodb] ; extra == 'testing'
|
24
|
+
Requires-Dist: moto[dynamodb] ==4.2.14 ; extra == 'testing'
|
24
25
|
|
25
26
|
.. image:: ./assets/logo.png
|
26
27
|
:alt: Statikk
|
@@ -0,0 +1,10 @@
|
|
1
|
+
statikk/__init__.py,sha256=pH5i4Fj1tbXLqLtTVIdoojiplZssQn0nnud8-HXodRE,577
|
2
|
+
statikk/conditions.py,sha256=66kJ-2YWqlV-dzEkiAe6c985dMQ-lpaoZ8aaoWhSs_M,2220
|
3
|
+
statikk/engine.py,sha256=aYIVTwUxlSLnoB8DOUpX4udf0PcIoiTzgSfJ3YCtPaU,22193
|
4
|
+
statikk/expressions.py,sha256=mF6Hmj3Kmj6KKXTymeTHSepVA7rhiSINpFgSAPeBTRY,12210
|
5
|
+
statikk/models.py,sha256=q-wY2bQRgaH0NTnR4NGnQ22eO3rUshK-aAykt7NVFO4,6172
|
6
|
+
statikk-0.0.12.dist-info/LICENSE.txt,sha256=uSH_2Hpb2Bigy5_HhBliN2fZbBU64G3ERM5zzhKPUEE,1078
|
7
|
+
statikk-0.0.12.dist-info/METADATA,sha256=KEEKDEMhWuuw_uSGW16PptvjXQIyMxi96Hh9Zg8Z4yI,3339
|
8
|
+
statikk-0.0.12.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
|
9
|
+
statikk-0.0.12.dist-info/top_level.txt,sha256=etKmBbjzIlLpSefXoiOfhWGEgvqUEALaFwCjFDBD9YI,8
|
10
|
+
statikk-0.0.12.dist-info/RECORD,,
|
statikk-0.0.10.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
statikk/__init__.py,sha256=pH5i4Fj1tbXLqLtTVIdoojiplZssQn0nnud8-HXodRE,577
|
2
|
-
statikk/conditions.py,sha256=66kJ-2YWqlV-dzEkiAe6c985dMQ-lpaoZ8aaoWhSs_M,2220
|
3
|
-
statikk/engine.py,sha256=7X4iAci6UBzpMkYtjS_da-iwNzf4zPbwkXvJ290IIdU,21767
|
4
|
-
statikk/expressions.py,sha256=mF6Hmj3Kmj6KKXTymeTHSepVA7rhiSINpFgSAPeBTRY,12210
|
5
|
-
statikk/models.py,sha256=q-wY2bQRgaH0NTnR4NGnQ22eO3rUshK-aAykt7NVFO4,6172
|
6
|
-
statikk-0.0.10.dist-info/LICENSE.txt,sha256=uSH_2Hpb2Bigy5_HhBliN2fZbBU64G3ERM5zzhKPUEE,1078
|
7
|
-
statikk-0.0.10.dist-info/METADATA,sha256=9miP26eX1SuDKFVoQNm7W-2j-ZCEFyLwheAQ8quO214,3293
|
8
|
-
statikk-0.0.10.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
9
|
-
statikk-0.0.10.dist-info/top_level.txt,sha256=etKmBbjzIlLpSefXoiOfhWGEgvqUEALaFwCjFDBD9YI,8
|
10
|
-
statikk-0.0.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|