dynamoxy 0.1.0__tar.gz → 0.3.0__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.
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/Cargo.lock +2 -17
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/Cargo.toml +2 -4
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/PKG-INFO +85 -30
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/README.md +84 -29
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/README.md +84 -29
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/aws/convert.rs +2 -1
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/memory/batch.rs +22 -16
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/memory/items.rs +40 -29
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/memory/mod.rs +200 -73
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/memory/partiql.rs +194 -32
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/memory/query.rs +198 -69
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/memory/table.rs +50 -18
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/memory/tests.rs +325 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/memory/transact.rs +61 -10
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/client/tests.rs +179 -1
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/client.rs +321 -91
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/config.rs +1 -1
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/error.rs +27 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/events.rs +1 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/expr/mod.rs +2 -2
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/expr/parser.rs +69 -67
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/expr/projection.rs +28 -9
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/expr/reserved.rs +15 -2
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/expr/update.rs +92 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/value/number.rs +149 -2
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-py/Cargo.toml +0 -1
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-py/src/client.rs +128 -98
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-py/src/convert.rs +194 -75
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-py/src/errors.rs +31 -10
- dynamoxy-0.3.0/crates/dynamoxy-py/src/runtime.rs +566 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/AGENT_GUIDE.md +159 -36
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/__init__.py +9 -1
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/_core.pyi +7 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/_pydantic.py +44 -6
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/_utils.py +42 -1
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/attributes.py +29 -4
- dynamoxy-0.3.0/python/dynamoxy/batch.py +186 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/client.py +196 -55
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/codecs.py +256 -33
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/collection.py +67 -12
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/constraints.py +10 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/errors.py +15 -7
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/events.py +55 -13
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/expressions.py +107 -15
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/middleware.py +37 -15
- dynamoxy-0.3.0/python/dynamoxy/models.py +892 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/query.py +274 -65
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/repository.py +609 -158
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/schema.py +323 -71
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/table.py +54 -7
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/telemetry.py +55 -3
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/testing.py +5 -1
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/transactions.py +28 -10
- dynamoxy-0.1.0/crates/dynamoxy-py/src/runtime.rs +0 -171
- dynamoxy-0.1.0/python/dynamoxy/batch.py +0 -135
- dynamoxy-0.1.0/python/dynamoxy/models.py +0 -461
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/LICENSE +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/Cargo.toml +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/aws/errors.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/aws/mod.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/memory/admin.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/backend/mod.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/expr/ast.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/expr/eval.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/expr/tests.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/lib.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/metrics.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/retry.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/types/mod.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/types/ops.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/types/schema.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/value/mod.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/src/value/size.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-core/tests/emulator.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/crates/dynamoxy-py/src/lib.rs +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/pyproject.toml +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/__main__.py +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/py.typed +0 -0
- {dynamoxy-0.1.0 → dynamoxy-0.3.0}/python/dynamoxy/results.py +0 -0
|
@@ -670,7 +670,7 @@ checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
|
|
|
670
670
|
|
|
671
671
|
[[package]]
|
|
672
672
|
name = "dynamoxy-core"
|
|
673
|
-
version = "0.
|
|
673
|
+
version = "0.3.0"
|
|
674
674
|
dependencies = [
|
|
675
675
|
"async-trait",
|
|
676
676
|
"aws-config",
|
|
@@ -686,12 +686,11 @@ dependencies = [
|
|
|
686
686
|
|
|
687
687
|
[[package]]
|
|
688
688
|
name = "dynamoxy-py"
|
|
689
|
-
version = "0.
|
|
689
|
+
version = "0.3.0"
|
|
690
690
|
dependencies = [
|
|
691
691
|
"dynamoxy-core",
|
|
692
692
|
"parking_lot",
|
|
693
693
|
"pyo3",
|
|
694
|
-
"pyo3-async-runtimes",
|
|
695
694
|
"pythonize",
|
|
696
695
|
"serde",
|
|
697
696
|
"tokio",
|
|
@@ -1394,20 +1393,6 @@ dependencies = [
|
|
|
1394
1393
|
"pyo3-macros",
|
|
1395
1394
|
]
|
|
1396
1395
|
|
|
1397
|
-
[[package]]
|
|
1398
|
-
name = "pyo3-async-runtimes"
|
|
1399
|
-
version = "0.29.0"
|
|
1400
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1401
|
-
checksum = "b3ef68daa7316a3fac65e5e18b2203f010346de1c1c53456811a2624673ab046"
|
|
1402
|
-
dependencies = [
|
|
1403
|
-
"futures-channel",
|
|
1404
|
-
"futures-util",
|
|
1405
|
-
"once_cell",
|
|
1406
|
-
"pin-project-lite",
|
|
1407
|
-
"pyo3",
|
|
1408
|
-
"tokio",
|
|
1409
|
-
]
|
|
1410
|
-
|
|
1411
1396
|
[[package]]
|
|
1412
1397
|
name = "pyo3-build-config"
|
|
1413
1398
|
version = "0.29.3"
|
|
@@ -4,7 +4,7 @@ members = ["crates/dynamoxy-core", "crates/dynamoxy-py"]
|
|
|
4
4
|
|
|
5
5
|
# The single version of the project: the Python package takes it from the binding crate.
|
|
6
6
|
[workspace.package]
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
edition = "2024"
|
|
9
9
|
rust-version = "1.94"
|
|
10
10
|
license = "MIT"
|
|
@@ -13,7 +13,7 @@ homepage = "https://github.com/kalaspuff/dynamoxy"
|
|
|
13
13
|
authors = ["Carl Oscar Aaro <hello@carloscar.com>"]
|
|
14
14
|
|
|
15
15
|
[workspace.dependencies]
|
|
16
|
-
dynamoxy-core = { path = "crates/dynamoxy-core", version = "0.
|
|
16
|
+
dynamoxy-core = { path = "crates/dynamoxy-core", version = "0.3.0" }
|
|
17
17
|
async-trait = "0.1"
|
|
18
18
|
aws-config = { version = "1.12", features = ["behavior-version-latest"] }
|
|
19
19
|
aws-credential-types = { version = "1.3", features = ["hardcoded-credentials"] }
|
|
@@ -21,8 +21,6 @@ aws-sdk-dynamodb = { version = "1.130", features = ["behavior-version-latest"] }
|
|
|
21
21
|
fastrand = "2"
|
|
22
22
|
parking_lot = "0.12"
|
|
23
23
|
pyo3 = { version = "0.29", features = ["abi3-py312"] }
|
|
24
|
-
# tokio-runtime: implements the bridge's JoinError trait for Tokio (needed by runtime.rs).
|
|
25
|
-
pyo3-async-runtimes = { version = "0.29", features = ["tokio-runtime"] }
|
|
26
24
|
pythonize = "0.29"
|
|
27
25
|
serde = { version = "1", features = ["derive"] }
|
|
28
26
|
thiserror = "2"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dynamoxy
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Classifier: Development Status :: 3 - Alpha
|
|
5
5
|
Classifier: Framework :: AsyncIO
|
|
6
6
|
Classifier: Framework :: Pydantic :: 2
|
|
@@ -39,12 +39,16 @@ Project-URL: Homepage, https://github.com/kalaspuff/dynamoxy
|
|
|
39
39
|
Project-URL: Issues, https://github.com/kalaspuff/dynamoxy/issues
|
|
40
40
|
Project-URL: Repository, https://github.com/kalaspuff/dynamoxy
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
<h1>
|
|
43
|
+
<picture>
|
|
44
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/kalaspuff/dynamoxy/main/docs/assets/logo/dynamoxy-dark.svg">
|
|
45
|
+
<img src="https://raw.githubusercontent.com/kalaspuff/dynamoxy/main/docs/assets/logo/dynamoxy.svg" alt="" width="44" height="44" align="absmiddle">
|
|
46
|
+
</picture>
|
|
47
|
+
dynamoxy
|
|
48
|
+
</h1>
|
|
43
49
|
|
|
44
50
|
**A typed, async DynamoDB ORM for Python, with a Rust core.** Declare models with type hints (or
|
|
45
|
-
pydantic)
|
|
46
|
-
cursors, transactions with readable failures, unique constraints, optimistic locking,
|
|
47
|
-
single-table design and an in-memory DynamoDB for tests.
|
|
51
|
+
pydantic) and get validated, atomic DynamoDB access, plus an in-memory DynamoDB for your tests.
|
|
48
52
|
|
|
49
53
|
```python
|
|
50
54
|
import asyncio
|
|
@@ -71,7 +75,9 @@ async def main() -> None:
|
|
|
71
75
|
users = client.repository(User)
|
|
72
76
|
|
|
73
77
|
ada = await users.create(User(user_id="u1", email="ada@example.com", name="Ada"))
|
|
74
|
-
await
|
|
78
|
+
await ada.increment(User.visits) # atomic; `ada` is refreshed in place
|
|
79
|
+
ada.name = "Ada Lovelace"
|
|
80
|
+
await ada.save() # only if nobody changed it meanwhile (version)
|
|
75
81
|
|
|
76
82
|
try:
|
|
77
83
|
await users.create(User(user_id="u2", email="ada@example.com", name="Imposter"))
|
|
@@ -85,6 +91,41 @@ async def main() -> None:
|
|
|
85
91
|
asyncio.run(main())
|
|
86
92
|
```
|
|
87
93
|
|
|
94
|
+
## Highlights
|
|
95
|
+
|
|
96
|
+
- **Typed end to end.** Fields are values on instances and typed paths on the class
|
|
97
|
+
(`User.visits > 3`). Your type checker catches `User(visits="3")` and `User.visits > "3"`.
|
|
98
|
+
- **Errors that tell you what to fix.** DynamoDB's rules are checked before a request is sent:
|
|
99
|
+
|
|
100
|
+
```text
|
|
101
|
+
ValidationError: the transaction has 120 operations (guard items of unique attributes included); DynamoDB allows 100
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
A refused write raises `ItemAlreadyExistsError`, `VersionConflictError` or
|
|
105
|
+
`UniqueConstraintError`, not a bare `ConditionalCheckFailedException`.
|
|
106
|
+
- **Writes that mean what they say.** `create()` never overwrites, `save()` checks the version,
|
|
107
|
+
`update()` is atomic without a read.
|
|
108
|
+
- **Unique values, timestamps and versions** are maintained for you.
|
|
109
|
+
- **Retries built in**, with backoff and jitter. Nothing fails silently.
|
|
110
|
+
- **An in-memory DynamoDB for tests.** No Docker, no AWS account. It refuses what DynamoDB
|
|
111
|
+
refuses, simulates faults and answers in microseconds:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
dynamoxy.testing.inject_fault(client, operation="GetItem", error="throttling", times=2)
|
|
115
|
+
with dynamoxy.collect() as usage:
|
|
116
|
+
user = await users.get("u1") # throttled twice, retried
|
|
117
|
+
assert usage.retries == 2
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
- **Observable.** Structured logs and event hooks out of the box; OpenTelemetry spans and metrics
|
|
121
|
+
when you configure it. Item contents are never logged.
|
|
122
|
+
- **Single-table design** with key templates such as `"CUSTOMER#{customer_id}"`.
|
|
123
|
+
- **Fast.** 2.5 to 5 times less client CPU per call than boto3 ([numbers](#performance)).
|
|
124
|
+
- **No required dependencies.** pydantic and OpenTelemetry are optional extras.
|
|
125
|
+
|
|
126
|
+
Also covered: indexes, cursors, batches, transactions, TTL, streams, backups, PartiQL and table
|
|
127
|
+
management.
|
|
128
|
+
|
|
88
129
|
## Already using pydantic?
|
|
89
130
|
|
|
90
131
|
Inherit from `dynamoxy.PydanticModel` instead of `BaseModel` and mark the key. Pydantic keeps
|
|
@@ -121,26 +162,6 @@ A model you would rather not touch can stay as it is: subclass it together with
|
|
|
121
162
|
`dynamoxy.PydanticModel` and re-declare only the fields that need a marker, such as the key (see
|
|
122
163
|
the [pydantic guide](https://github.com/kalaspuff/dynamoxy/blob/main/docs/guides/pydantic.md#existing-models)).
|
|
123
164
|
|
|
124
|
-
## Why dynamoxy
|
|
125
|
-
|
|
126
|
-
- **Typed models**: `Attr[T]` fields are values on instances and typed expression paths on the
|
|
127
|
-
class (`User.visits > 3`); type checkers understand constructors and expressions. Pydantic
|
|
128
|
-
models work too.
|
|
129
|
-
- **Correct by default**: validation before I/O, `create` that never overwrites, optimistic
|
|
130
|
-
locking with `version()`, unique attributes enforced transactionally, automatic timestamps,
|
|
131
|
-
conditions on every write, no values in expression strings.
|
|
132
|
-
- **Every DynamoDB feature**: queries and scans with cursors, global and local indexes,
|
|
133
|
-
batches with unprocessed-item handling, transactions with per-operation cancellation reasons,
|
|
134
|
-
TTL, streams, backups and point-in-time recovery, PartiQL, table management.
|
|
135
|
-
- **Single-table design** with key templates, derived index keys and mixed-entity collections.
|
|
136
|
-
- **Observable**: structured events and logging, hooks, middleware, OpenTelemetry spans and
|
|
137
|
-
metrics, per-request cost accounting (`dynamoxy.collect()`).
|
|
138
|
-
- **Testable**: `dynamoxy.testing.memory_client()` is an in-memory DynamoDB with DynamoDB's
|
|
139
|
-
semantics and fault injection; no Docker, no AWS account.
|
|
140
|
-
- **Fast and robust**: a Rust core (AWS SDK for Rust, Tokio) handles transport, retries with
|
|
141
|
-
backoff, timeouts and batching; wheels for Linux (x86_64, aarch64, glibc and musl), macOS and
|
|
142
|
-
Windows, CPython 3.12+.
|
|
143
|
-
|
|
144
165
|
## Install
|
|
145
166
|
|
|
146
167
|
```bash
|
|
@@ -168,10 +189,44 @@ before writing code with dynamoxy; application repositories can copy the skill i
|
|
|
168
189
|
|
|
169
190
|
## How it works
|
|
170
191
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
192
|
+
A Rust core speaks DynamoDB: the AWS SDK for transport, plus dynamoxy's own retries, batching,
|
|
193
|
+
events and the in-memory backend. Python owns what you touch: models, validation, repositories
|
|
194
|
+
and hooks. A few choices worth knowing:
|
|
195
|
+
|
|
196
|
+
- **Values never go into expression strings**, so reserved words and injection are non-issues.
|
|
197
|
+
- **Unique values are guard items** written in the same transaction, since indexes are only
|
|
198
|
+
eventually consistent.
|
|
199
|
+
- **Models hold no client**, so one model works with several accounts, regions or test stores.
|
|
200
|
+
- **Stored formats are API**: they stay readable across versions.
|
|
201
|
+
|
|
202
|
+
The [architecture](https://github.com/kalaspuff/dynamoxy/blob/main/docs/architecture.md) and the
|
|
203
|
+
[decision records](https://github.com/kalaspuff/dynamoxy/blob/main/docs/adr/README.md) have the
|
|
204
|
+
details.
|
|
205
|
+
|
|
206
|
+
## Performance
|
|
207
|
+
|
|
208
|
+
Round trips cost every client the same. What a library adds is CPU time per call, spent holding
|
|
209
|
+
the GIL. dynamoxy does the protocol work in Rust.
|
|
210
|
+
|
|
211
|
+
Client CPU time per call against a local emulator (dynamoxy returns validated models; the others
|
|
212
|
+
return DynamoDB JSON):
|
|
213
|
+
|
|
214
|
+
| | dynamoxy | boto3 | aiobotocore |
|
|
215
|
+
| --- | ---: | ---: | ---: |
|
|
216
|
+
| `GetItem`, one item | 0.14 ms | 0.66 ms | 0.60 ms |
|
|
217
|
+
| `PutItem`, one item | 0.19 ms | 0.67 ms | 0.61 ms |
|
|
218
|
+
| `Query`, 100 items | 0.65 ms | 1.68 ms | 1.71 ms |
|
|
219
|
+
|
|
220
|
+
- **Cold start** (import and first read): 51 ms, against 115 ms for boto3.
|
|
221
|
+
- **In memory**, a `get()` takes about 13 µs, so large test suites run in seconds.
|
|
222
|
+
|
|
223
|
+
Why it is fast: signing, HTTP, JSON and retries run in Rust outside the GIL; each model plans its
|
|
224
|
+
encoding once, when the class is created; and features you do not use cost nothing.
|
|
225
|
+
|
|
226
|
+
Measured with dynamoxy 0.2.0 on Python 3.14, aarch64 Linux, October 2026. Your hardware will
|
|
227
|
+
differ:
|
|
228
|
+
[`scripts/benchmark.py`](https://github.com/kalaspuff/dynamoxy/blob/main/scripts/benchmark.py)
|
|
229
|
+
measures it on yours.
|
|
175
230
|
|
|
176
231
|
## Contributing
|
|
177
232
|
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
<h1>
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/kalaspuff/dynamoxy/main/docs/assets/logo/dynamoxy-dark.svg">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/kalaspuff/dynamoxy/main/docs/assets/logo/dynamoxy.svg" alt="" width="44" height="44" align="absmiddle">
|
|
5
|
+
</picture>
|
|
6
|
+
dynamoxy
|
|
7
|
+
</h1>
|
|
2
8
|
|
|
3
9
|
**A typed, async DynamoDB ORM for Python, with a Rust core.** Declare models with type hints (or
|
|
4
|
-
pydantic)
|
|
5
|
-
cursors, transactions with readable failures, unique constraints, optimistic locking,
|
|
6
|
-
single-table design and an in-memory DynamoDB for tests.
|
|
10
|
+
pydantic) and get validated, atomic DynamoDB access, plus an in-memory DynamoDB for your tests.
|
|
7
11
|
|
|
8
12
|
```python
|
|
9
13
|
import asyncio
|
|
@@ -30,7 +34,9 @@ async def main() -> None:
|
|
|
30
34
|
users = client.repository(User)
|
|
31
35
|
|
|
32
36
|
ada = await users.create(User(user_id="u1", email="ada@example.com", name="Ada"))
|
|
33
|
-
await
|
|
37
|
+
await ada.increment(User.visits) # atomic; `ada` is refreshed in place
|
|
38
|
+
ada.name = "Ada Lovelace"
|
|
39
|
+
await ada.save() # only if nobody changed it meanwhile (version)
|
|
34
40
|
|
|
35
41
|
try:
|
|
36
42
|
await users.create(User(user_id="u2", email="ada@example.com", name="Imposter"))
|
|
@@ -44,6 +50,41 @@ async def main() -> None:
|
|
|
44
50
|
asyncio.run(main())
|
|
45
51
|
```
|
|
46
52
|
|
|
53
|
+
## Highlights
|
|
54
|
+
|
|
55
|
+
- **Typed end to end.** Fields are values on instances and typed paths on the class
|
|
56
|
+
(`User.visits > 3`). Your type checker catches `User(visits="3")` and `User.visits > "3"`.
|
|
57
|
+
- **Errors that tell you what to fix.** DynamoDB's rules are checked before a request is sent:
|
|
58
|
+
|
|
59
|
+
```text
|
|
60
|
+
ValidationError: the transaction has 120 operations (guard items of unique attributes included); DynamoDB allows 100
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
A refused write raises `ItemAlreadyExistsError`, `VersionConflictError` or
|
|
64
|
+
`UniqueConstraintError`, not a bare `ConditionalCheckFailedException`.
|
|
65
|
+
- **Writes that mean what they say.** `create()` never overwrites, `save()` checks the version,
|
|
66
|
+
`update()` is atomic without a read.
|
|
67
|
+
- **Unique values, timestamps and versions** are maintained for you.
|
|
68
|
+
- **Retries built in**, with backoff and jitter. Nothing fails silently.
|
|
69
|
+
- **An in-memory DynamoDB for tests.** No Docker, no AWS account. It refuses what DynamoDB
|
|
70
|
+
refuses, simulates faults and answers in microseconds:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
dynamoxy.testing.inject_fault(client, operation="GetItem", error="throttling", times=2)
|
|
74
|
+
with dynamoxy.collect() as usage:
|
|
75
|
+
user = await users.get("u1") # throttled twice, retried
|
|
76
|
+
assert usage.retries == 2
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- **Observable.** Structured logs and event hooks out of the box; OpenTelemetry spans and metrics
|
|
80
|
+
when you configure it. Item contents are never logged.
|
|
81
|
+
- **Single-table design** with key templates such as `"CUSTOMER#{customer_id}"`.
|
|
82
|
+
- **Fast.** 2.5 to 5 times less client CPU per call than boto3 ([numbers](#performance)).
|
|
83
|
+
- **No required dependencies.** pydantic and OpenTelemetry are optional extras.
|
|
84
|
+
|
|
85
|
+
Also covered: indexes, cursors, batches, transactions, TTL, streams, backups, PartiQL and table
|
|
86
|
+
management.
|
|
87
|
+
|
|
47
88
|
## Already using pydantic?
|
|
48
89
|
|
|
49
90
|
Inherit from `dynamoxy.PydanticModel` instead of `BaseModel` and mark the key. Pydantic keeps
|
|
@@ -80,26 +121,6 @@ A model you would rather not touch can stay as it is: subclass it together with
|
|
|
80
121
|
`dynamoxy.PydanticModel` and re-declare only the fields that need a marker, such as the key (see
|
|
81
122
|
the [pydantic guide](https://github.com/kalaspuff/dynamoxy/blob/main/docs/guides/pydantic.md#existing-models)).
|
|
82
123
|
|
|
83
|
-
## Why dynamoxy
|
|
84
|
-
|
|
85
|
-
- **Typed models**: `Attr[T]` fields are values on instances and typed expression paths on the
|
|
86
|
-
class (`User.visits > 3`); type checkers understand constructors and expressions. Pydantic
|
|
87
|
-
models work too.
|
|
88
|
-
- **Correct by default**: validation before I/O, `create` that never overwrites, optimistic
|
|
89
|
-
locking with `version()`, unique attributes enforced transactionally, automatic timestamps,
|
|
90
|
-
conditions on every write, no values in expression strings.
|
|
91
|
-
- **Every DynamoDB feature**: queries and scans with cursors, global and local indexes,
|
|
92
|
-
batches with unprocessed-item handling, transactions with per-operation cancellation reasons,
|
|
93
|
-
TTL, streams, backups and point-in-time recovery, PartiQL, table management.
|
|
94
|
-
- **Single-table design** with key templates, derived index keys and mixed-entity collections.
|
|
95
|
-
- **Observable**: structured events and logging, hooks, middleware, OpenTelemetry spans and
|
|
96
|
-
metrics, per-request cost accounting (`dynamoxy.collect()`).
|
|
97
|
-
- **Testable**: `dynamoxy.testing.memory_client()` is an in-memory DynamoDB with DynamoDB's
|
|
98
|
-
semantics and fault injection; no Docker, no AWS account.
|
|
99
|
-
- **Fast and robust**: a Rust core (AWS SDK for Rust, Tokio) handles transport, retries with
|
|
100
|
-
backoff, timeouts and batching; wheels for Linux (x86_64, aarch64, glibc and musl), macOS and
|
|
101
|
-
Windows, CPython 3.12+.
|
|
102
|
-
|
|
103
124
|
## Install
|
|
104
125
|
|
|
105
126
|
```bash
|
|
@@ -127,10 +148,44 @@ before writing code with dynamoxy; application repositories can copy the skill i
|
|
|
127
148
|
|
|
128
149
|
## How it works
|
|
129
150
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
151
|
+
A Rust core speaks DynamoDB: the AWS SDK for transport, plus dynamoxy's own retries, batching,
|
|
152
|
+
events and the in-memory backend. Python owns what you touch: models, validation, repositories
|
|
153
|
+
and hooks. A few choices worth knowing:
|
|
154
|
+
|
|
155
|
+
- **Values never go into expression strings**, so reserved words and injection are non-issues.
|
|
156
|
+
- **Unique values are guard items** written in the same transaction, since indexes are only
|
|
157
|
+
eventually consistent.
|
|
158
|
+
- **Models hold no client**, so one model works with several accounts, regions or test stores.
|
|
159
|
+
- **Stored formats are API**: they stay readable across versions.
|
|
160
|
+
|
|
161
|
+
The [architecture](https://github.com/kalaspuff/dynamoxy/blob/main/docs/architecture.md) and the
|
|
162
|
+
[decision records](https://github.com/kalaspuff/dynamoxy/blob/main/docs/adr/README.md) have the
|
|
163
|
+
details.
|
|
164
|
+
|
|
165
|
+
## Performance
|
|
166
|
+
|
|
167
|
+
Round trips cost every client the same. What a library adds is CPU time per call, spent holding
|
|
168
|
+
the GIL. dynamoxy does the protocol work in Rust.
|
|
169
|
+
|
|
170
|
+
Client CPU time per call against a local emulator (dynamoxy returns validated models; the others
|
|
171
|
+
return DynamoDB JSON):
|
|
172
|
+
|
|
173
|
+
| | dynamoxy | boto3 | aiobotocore |
|
|
174
|
+
| --- | ---: | ---: | ---: |
|
|
175
|
+
| `GetItem`, one item | 0.14 ms | 0.66 ms | 0.60 ms |
|
|
176
|
+
| `PutItem`, one item | 0.19 ms | 0.67 ms | 0.61 ms |
|
|
177
|
+
| `Query`, 100 items | 0.65 ms | 1.68 ms | 1.71 ms |
|
|
178
|
+
|
|
179
|
+
- **Cold start** (import and first read): 51 ms, against 115 ms for boto3.
|
|
180
|
+
- **In memory**, a `get()` takes about 13 µs, so large test suites run in seconds.
|
|
181
|
+
|
|
182
|
+
Why it is fast: signing, HTTP, JSON and retries run in Rust outside the GIL; each model plans its
|
|
183
|
+
encoding once, when the class is created; and features you do not use cost nothing.
|
|
184
|
+
|
|
185
|
+
Measured with dynamoxy 0.2.0 on Python 3.14, aarch64 Linux, October 2026. Your hardware will
|
|
186
|
+
differ:
|
|
187
|
+
[`scripts/benchmark.py`](https://github.com/kalaspuff/dynamoxy/blob/main/scripts/benchmark.py)
|
|
188
|
+
measures it on yours.
|
|
134
189
|
|
|
135
190
|
## Contributing
|
|
136
191
|
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
<h1>
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/kalaspuff/dynamoxy/main/docs/assets/logo/dynamoxy-dark.svg">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/kalaspuff/dynamoxy/main/docs/assets/logo/dynamoxy.svg" alt="" width="44" height="44" align="absmiddle">
|
|
5
|
+
</picture>
|
|
6
|
+
dynamoxy
|
|
7
|
+
</h1>
|
|
2
8
|
|
|
3
9
|
**A typed, async DynamoDB ORM for Python, with a Rust core.** Declare models with type hints (or
|
|
4
|
-
pydantic)
|
|
5
|
-
cursors, transactions with readable failures, unique constraints, optimistic locking,
|
|
6
|
-
single-table design and an in-memory DynamoDB for tests.
|
|
10
|
+
pydantic) and get validated, atomic DynamoDB access, plus an in-memory DynamoDB for your tests.
|
|
7
11
|
|
|
8
12
|
```python
|
|
9
13
|
import asyncio
|
|
@@ -30,7 +34,9 @@ async def main() -> None:
|
|
|
30
34
|
users = client.repository(User)
|
|
31
35
|
|
|
32
36
|
ada = await users.create(User(user_id="u1", email="ada@example.com", name="Ada"))
|
|
33
|
-
await
|
|
37
|
+
await ada.increment(User.visits) # atomic; `ada` is refreshed in place
|
|
38
|
+
ada.name = "Ada Lovelace"
|
|
39
|
+
await ada.save() # only if nobody changed it meanwhile (version)
|
|
34
40
|
|
|
35
41
|
try:
|
|
36
42
|
await users.create(User(user_id="u2", email="ada@example.com", name="Imposter"))
|
|
@@ -44,6 +50,41 @@ async def main() -> None:
|
|
|
44
50
|
asyncio.run(main())
|
|
45
51
|
```
|
|
46
52
|
|
|
53
|
+
## Highlights
|
|
54
|
+
|
|
55
|
+
- **Typed end to end.** Fields are values on instances and typed paths on the class
|
|
56
|
+
(`User.visits > 3`). Your type checker catches `User(visits="3")` and `User.visits > "3"`.
|
|
57
|
+
- **Errors that tell you what to fix.** DynamoDB's rules are checked before a request is sent:
|
|
58
|
+
|
|
59
|
+
```text
|
|
60
|
+
ValidationError: the transaction has 120 operations (guard items of unique attributes included); DynamoDB allows 100
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
A refused write raises `ItemAlreadyExistsError`, `VersionConflictError` or
|
|
64
|
+
`UniqueConstraintError`, not a bare `ConditionalCheckFailedException`.
|
|
65
|
+
- **Writes that mean what they say.** `create()` never overwrites, `save()` checks the version,
|
|
66
|
+
`update()` is atomic without a read.
|
|
67
|
+
- **Unique values, timestamps and versions** are maintained for you.
|
|
68
|
+
- **Retries built in**, with backoff and jitter. Nothing fails silently.
|
|
69
|
+
- **An in-memory DynamoDB for tests.** No Docker, no AWS account. It refuses what DynamoDB
|
|
70
|
+
refuses, simulates faults and answers in microseconds:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
dynamoxy.testing.inject_fault(client, operation="GetItem", error="throttling", times=2)
|
|
74
|
+
with dynamoxy.collect() as usage:
|
|
75
|
+
user = await users.get("u1") # throttled twice, retried
|
|
76
|
+
assert usage.retries == 2
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- **Observable.** Structured logs and event hooks out of the box; OpenTelemetry spans and metrics
|
|
80
|
+
when you configure it. Item contents are never logged.
|
|
81
|
+
- **Single-table design** with key templates such as `"CUSTOMER#{customer_id}"`.
|
|
82
|
+
- **Fast.** 2.5 to 5 times less client CPU per call than boto3 ([numbers](#performance)).
|
|
83
|
+
- **No required dependencies.** pydantic and OpenTelemetry are optional extras.
|
|
84
|
+
|
|
85
|
+
Also covered: indexes, cursors, batches, transactions, TTL, streams, backups, PartiQL and table
|
|
86
|
+
management.
|
|
87
|
+
|
|
47
88
|
## Already using pydantic?
|
|
48
89
|
|
|
49
90
|
Inherit from `dynamoxy.PydanticModel` instead of `BaseModel` and mark the key. Pydantic keeps
|
|
@@ -80,26 +121,6 @@ A model you would rather not touch can stay as it is: subclass it together with
|
|
|
80
121
|
`dynamoxy.PydanticModel` and re-declare only the fields that need a marker, such as the key (see
|
|
81
122
|
the [pydantic guide](https://github.com/kalaspuff/dynamoxy/blob/main/docs/guides/pydantic.md#existing-models)).
|
|
82
123
|
|
|
83
|
-
## Why dynamoxy
|
|
84
|
-
|
|
85
|
-
- **Typed models**: `Attr[T]` fields are values on instances and typed expression paths on the
|
|
86
|
-
class (`User.visits > 3`); type checkers understand constructors and expressions. Pydantic
|
|
87
|
-
models work too.
|
|
88
|
-
- **Correct by default**: validation before I/O, `create` that never overwrites, optimistic
|
|
89
|
-
locking with `version()`, unique attributes enforced transactionally, automatic timestamps,
|
|
90
|
-
conditions on every write, no values in expression strings.
|
|
91
|
-
- **Every DynamoDB feature**: queries and scans with cursors, global and local indexes,
|
|
92
|
-
batches with unprocessed-item handling, transactions with per-operation cancellation reasons,
|
|
93
|
-
TTL, streams, backups and point-in-time recovery, PartiQL, table management.
|
|
94
|
-
- **Single-table design** with key templates, derived index keys and mixed-entity collections.
|
|
95
|
-
- **Observable**: structured events and logging, hooks, middleware, OpenTelemetry spans and
|
|
96
|
-
metrics, per-request cost accounting (`dynamoxy.collect()`).
|
|
97
|
-
- **Testable**: `dynamoxy.testing.memory_client()` is an in-memory DynamoDB with DynamoDB's
|
|
98
|
-
semantics and fault injection; no Docker, no AWS account.
|
|
99
|
-
- **Fast and robust**: a Rust core (AWS SDK for Rust, Tokio) handles transport, retries with
|
|
100
|
-
backoff, timeouts and batching; wheels for Linux (x86_64, aarch64, glibc and musl), macOS and
|
|
101
|
-
Windows, CPython 3.12+.
|
|
102
|
-
|
|
103
124
|
## Install
|
|
104
125
|
|
|
105
126
|
```bash
|
|
@@ -127,10 +148,44 @@ before writing code with dynamoxy; application repositories can copy the skill i
|
|
|
127
148
|
|
|
128
149
|
## How it works
|
|
129
150
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
151
|
+
A Rust core speaks DynamoDB: the AWS SDK for transport, plus dynamoxy's own retries, batching,
|
|
152
|
+
events and the in-memory backend. Python owns what you touch: models, validation, repositories
|
|
153
|
+
and hooks. A few choices worth knowing:
|
|
154
|
+
|
|
155
|
+
- **Values never go into expression strings**, so reserved words and injection are non-issues.
|
|
156
|
+
- **Unique values are guard items** written in the same transaction, since indexes are only
|
|
157
|
+
eventually consistent.
|
|
158
|
+
- **Models hold no client**, so one model works with several accounts, regions or test stores.
|
|
159
|
+
- **Stored formats are API**: they stay readable across versions.
|
|
160
|
+
|
|
161
|
+
The [architecture](https://github.com/kalaspuff/dynamoxy/blob/main/docs/architecture.md) and the
|
|
162
|
+
[decision records](https://github.com/kalaspuff/dynamoxy/blob/main/docs/adr/README.md) have the
|
|
163
|
+
details.
|
|
164
|
+
|
|
165
|
+
## Performance
|
|
166
|
+
|
|
167
|
+
Round trips cost every client the same. What a library adds is CPU time per call, spent holding
|
|
168
|
+
the GIL. dynamoxy does the protocol work in Rust.
|
|
169
|
+
|
|
170
|
+
Client CPU time per call against a local emulator (dynamoxy returns validated models; the others
|
|
171
|
+
return DynamoDB JSON):
|
|
172
|
+
|
|
173
|
+
| | dynamoxy | boto3 | aiobotocore |
|
|
174
|
+
| --- | ---: | ---: | ---: |
|
|
175
|
+
| `GetItem`, one item | 0.14 ms | 0.66 ms | 0.60 ms |
|
|
176
|
+
| `PutItem`, one item | 0.19 ms | 0.67 ms | 0.61 ms |
|
|
177
|
+
| `Query`, 100 items | 0.65 ms | 1.68 ms | 1.71 ms |
|
|
178
|
+
|
|
179
|
+
- **Cold start** (import and first read): 51 ms, against 115 ms for boto3.
|
|
180
|
+
- **In memory**, a `get()` takes about 13 µs, so large test suites run in seconds.
|
|
181
|
+
|
|
182
|
+
Why it is fast: signing, HTTP, JSON and retries run in Rust outside the GIL; each model plans its
|
|
183
|
+
encoding once, when the class is created; and features you do not use cost nothing.
|
|
184
|
+
|
|
185
|
+
Measured with dynamoxy 0.2.0 on Python 3.14, aarch64 Linux, October 2026. Your hardware will
|
|
186
|
+
differ:
|
|
187
|
+
[`scripts/benchmark.py`](https://github.com/kalaspuff/dynamoxy/blob/main/scripts/benchmark.py)
|
|
188
|
+
measures it on yours.
|
|
134
189
|
|
|
135
190
|
## Contributing
|
|
136
191
|
|
|
@@ -54,7 +54,8 @@ pub fn item_to_sdk(item: Item) -> HashMap<String, sdk::AttributeValue> {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
fn number(text: String) -> Result<Number> {
|
|
57
|
-
|
|
57
|
+
// DynamoDB returns canonical numbers: they are kept as they are, without a copy.
|
|
58
|
+
Number::parse_owned(text).map_err(|error| protocol_error(format!("invalid number: {error}")))
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/// Converts a value from the SDK's representation.
|
|
@@ -7,7 +7,7 @@ use super::State;
|
|
|
7
7
|
use super::items::{Failure, apply, prepare_delete, prepare_put};
|
|
8
8
|
use super::table::{CapacityMeter, StoredKey, read_units};
|
|
9
9
|
use crate::error::{Error, Result};
|
|
10
|
-
use crate::expr::{ExpressionInput,
|
|
10
|
+
use crate::expr::{ExpressionInput, Projector, parse_request};
|
|
11
11
|
use crate::types::{
|
|
12
12
|
BatchGetItemInput, BatchGetItemOutput, BatchWriteItemInput, BatchWriteItemOutput, KeysAndAttributes,
|
|
13
13
|
ReturnValuesOnConditionCheckFailure, WriteRequest,
|
|
@@ -32,7 +32,7 @@ pub fn batch_get_item(state: &State, input: &BatchGetItemInput, unprocessed: boo
|
|
|
32
32
|
if total > 100 {
|
|
33
33
|
return Err(invalid("Too many items requested for the BatchGetItem call"));
|
|
34
34
|
}
|
|
35
|
-
let mut
|
|
35
|
+
let mut parsed = Vec::with_capacity(input.request_items.len());
|
|
36
36
|
for (table_name, request) in &input.request_items {
|
|
37
37
|
if request.keys.is_empty() {
|
|
38
38
|
return Err(invalid(format!(
|
|
@@ -40,18 +40,23 @@ pub fn batch_get_item(state: &State, input: &BatchGetItemInput, unprocessed: boo
|
|
|
40
40
|
)));
|
|
41
41
|
}
|
|
42
42
|
let table = state.table(table_name)?;
|
|
43
|
-
let mut
|
|
44
|
-
for key in
|
|
45
|
-
if
|
|
43
|
+
let mut positions = BTreeMap::new();
|
|
44
|
+
for (position, key) in request.keys.iter().enumerate() {
|
|
45
|
+
if positions.insert(table.key.exact_key(key)?, position).is_some() {
|
|
46
46
|
return Err(invalid("Provided list of item keys contains duplicates"));
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
let
|
|
49
|
+
let mut stored: Vec<Option<StoredKey>> = vec![None; request.keys.len()];
|
|
50
|
+
for (key, position) in positions {
|
|
51
|
+
stored[position] = Some(key);
|
|
52
|
+
}
|
|
53
|
+
let projection = parse_request(
|
|
50
54
|
ExpressionInput { projection: request.projection_expression.as_deref(), ..Default::default() },
|
|
51
55
|
&request.expression_attribute_names,
|
|
52
56
|
&Default::default(),
|
|
53
|
-
)
|
|
54
|
-
|
|
57
|
+
)?
|
|
58
|
+
.projection;
|
|
59
|
+
parsed.push((stored, projection.as_deref().map(Projector::new)));
|
|
55
60
|
}
|
|
56
61
|
let mut output = BatchGetItemOutput::default();
|
|
57
62
|
if unprocessed {
|
|
@@ -60,10 +65,9 @@ pub fn batch_get_item(state: &State, input: &BatchGetItemInput, unprocessed: boo
|
|
|
60
65
|
}
|
|
61
66
|
let mut meter = CapacityMeter::default();
|
|
62
67
|
let mut returned = 0usize;
|
|
63
|
-
for (table_name, request) in
|
|
68
|
+
for ((table_name, request), (stored_keys, projection)) in input.request_items.iter().zip(&parsed) {
|
|
64
69
|
let table = state.table(table_name)?;
|
|
65
|
-
|
|
66
|
-
for key in &request.keys {
|
|
70
|
+
for (key, stored) in request.keys.iter().zip(stored_keys) {
|
|
67
71
|
if returned >= RESPONSE_SIZE_LIMIT {
|
|
68
72
|
output
|
|
69
73
|
.unprocessed_keys
|
|
@@ -73,12 +77,11 @@ pub fn batch_get_item(state: &State, input: &BatchGetItemInput, unprocessed: boo
|
|
|
73
77
|
.push(key.clone());
|
|
74
78
|
continue;
|
|
75
79
|
}
|
|
76
|
-
let
|
|
77
|
-
let found = table.items.get(&stored);
|
|
80
|
+
let found = stored.as_ref().and_then(|stored| table.items.get(stored));
|
|
78
81
|
meter.read(table_name, None, read_units(found.map_or(0, item_size), request.consistent_read));
|
|
79
82
|
if let Some(item) = found {
|
|
80
83
|
let item = match projection {
|
|
81
|
-
Some(
|
|
84
|
+
Some(projector) => projector.apply(item),
|
|
82
85
|
None => item.clone(),
|
|
83
86
|
};
|
|
84
87
|
returned += item_size(&item);
|
|
@@ -142,8 +145,11 @@ pub fn batch_write_item(
|
|
|
142
145
|
for write in prepared {
|
|
143
146
|
if input.return_item_collection_metrics
|
|
144
147
|
&& let Some(table) = state.tables.get(&write.table)
|
|
145
|
-
&& let Some(metrics) =
|
|
146
|
-
|
|
148
|
+
&& let Some(metrics) = write
|
|
149
|
+
.new
|
|
150
|
+
.as_ref()
|
|
151
|
+
.or_else(|| table.items.get(&write.key))
|
|
152
|
+
.and_then(|item| table.item_collection_metrics(item))
|
|
147
153
|
{
|
|
148
154
|
output.item_collection_metrics.entry(write.table.clone()).or_default().push(metrics);
|
|
149
155
|
}
|