-
Notifications
You must be signed in to change notification settings - Fork 0
Adapter: Batch builders
See also (AWS JS SDK v3):
BatchWriteCommand·TransactWriteCommand·BatchGetCommand. Vocabulary: Concepts.
The Adapter exposes make*() builders that return discriminated descriptors {action, params} (or {action, adapter, params} for makeGet). Compose with applyBatch / applyTransaction from Batch and transactions to issue one DynamoDB call covering many ops.
| Builder | Returns | Notes |
|---|---|---|
makeGet(key, fields?, params?) |
{action: 'get', adapter, params} |
For use with getBatch / getTransaction
|
makeCheck(key, params?) |
{action: 'check', params} |
Condition-only; for use with applyTransaction
|
makePost(item, options?) |
{action: 'put', params} |
Adds attribute_not_exists
|
makePut(item, options?) |
{action: 'put', params} |
options.force skips existence check |
makePatch(key, patch, options?) |
{action: 'patch', params} |
Builds UpdateExpression
|
makeDelete(key, options?) |
{action: 'delete', params} |
All builders run the relevant hooks (prepare, validateItem, updateInput) and pass the result through cleanParams. makePost / makePut / makePatch / makeDelete accept {returnFailedItem: true} to surface the conflicting item on a failed conditional check — see Adapter: CRUD methods § returnFailedItem.
import {applyTransaction} from 'dynamodb-toolkit/batch';
// Atomically: post a child planet AND increment a parent's count
const child = await adapter.makePost({name: 'Mustafar', parent: 'Sol'});
const parentBump = await adapter.makePatch(
{name: 'Sol'},
{},
{arrayOps: [{op: 'add', path: 'children', value: 1}]}
);
await applyTransaction(adapter.client, child, parentBump);import {getBatch} from 'dynamodb-toolkit/batch';
const planetsAdapter = new Adapter({client, table: 'planets', keyFields: ['name']});
const moonsAdapter = new Adapter({client, table: 'moons', keyFields: ['planet', 'name']});
const results = await getBatch(
client,
await planetsAdapter.makeGet({name: 'Endor'}),
await moonsAdapter.makeGet({planet: 'Endor', name: 'Sanctuary'})
);
// → [{table: 'planets', item: {...}}, {table: 'moons', item: {...}}]-
Single op? Call
adapter.put(...)/adapter.patch(...)directly. Auto-upgrade and dispatch are handled. -
Multiple ops in one call? Build descriptors with
make*(), then dispatch withapplyBatch/applyTransaction/getBatch/getTransaction. -
Custom consistency checks? Use
makeCheck(key, {ConditionExpression: ...})and bundle with the main op viaapplyTransaction.
Start here
- Getting started
- Concepts
- Key and field design
- Compatibility
- Migration: v2 to v3
- SDK v2 to v3 cheat sheet
Guides
- Hierarchical data walkthrough
- Key expression patterns
- Multi-type tables
- Pagination
- Mass operation semantics
- URL schema design
Adapter
- Adapter
- Constructor options
- CRUD methods
- Mass methods
- Batch builders
- Hooks
- Raw marker
- Indirect indices
- Transaction auto-upgrade
Expression builders
Batch / transactions / mass / paths
REST surface
Framework adapters
Recipes
- Recipes index
- List records of a tier
- Per-tier sparse GSI markers
- Tier within a partition
- Reservation with auto-release
- Keys-only GSI, runtime projection
- Cascade subtree operations
- Querying subtrees with buildKey
- Filter URL grammar
- Text search
- Provisioning workflow
- Resumable mass operations
History