-
Notifications
You must be signed in to change notification settings - Fork 0
Mass operations
dynamodb-toolkit/mass exports primitives the Adapter composes for its mass methods (see Adapter:-Mass-methods). Use them directly when you need finer control or when you don't have an Adapter.
import {
paginateList, iterateList, iterateItems,
readList, readListGetItems, readListByKeys, readOrderedListByKeys,
writeList, deleteList, deleteListByKeys,
copyList, moveList, getTotal
} from 'dynamodb-toolkit/mass';Offset/limit pagination over a Query or Scan. Returns {data, offset, limit, total?}.
When params.FilterExpression is set, paginateList accumulates matches across pages — DynamoDB's Limit is pre-filter, so naive use returns short pages and false-empty results. paginateList paginates until enough matches are accumulated.
const r = await paginateList(client, {TableName: 'planets'}, {offset: 0, limit: 10});
// → {data: [...10 items...], offset: 0, limit: 10, total: 61}needTotal: false skips the Select: 'COUNT' round trips for the rest of the dataset — much cheaper for endless-scroll feeds.
Async generators. iterateList yields raw page objects; iterateItems yields individual items.
for await (const item of iterateItems(client, {TableName: 'planets'})) {
console.log(item.name);
}readList calls fn(page) once, then returns nextParams | null for chaining. readListGetItems returns {nextParams, items} directly.
Wrapper over getBatch that returns just the items as a plain array.
const items = await readListByKeys(client, 'planets', [{name: 'Hoth'}, {name: 'Bespin'}]);Same but preserves caller key order, with undefined for missing keys. The SDK's BatchGetItem returns items in arbitrary order — this helper rebuilds the original order.
const items = await readOrderedListByKeys(client, 'planets', [{name: 'A'}, {name: 'B'}, {name: 'C'}]);
// items[0] is A, items[1] is B, items[2] is C — or undefined for missesBatchWriteItem puts. Returns the count of items processed.
await writeList(client, 'planets', planets, item => ({...item, '-t': 1}));deleteList reads via scan/query then batch-deletes the matching keys. keyFn extracts the key from each item.
deleteListByKeys batch-deletes a list of keys directly.
Read items via scan/query, optionally transform, batch-write back to the same table.
Read via scan/query, paired puts + deletes per chunk (12 puts + 12 deletes per BatchWrite to stay under the 25-action limit). Returns the total batch-actions count (puts + deletes).
Select: 'COUNT' pagination — counts items matching the query/scan without returning them. Useful for the total in pagination envelopes when needTotal: true.
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