Token-aware reads and convenient batches with strong types.
Token-aware getItem/getItems
// Record shape narrowed by the literal entity token
const rec = await client.getItem('user', { hashKey2: 'h', rangeKey: 'r' });
const item = rec.Item && client.entityManager.removeKeys('user', rec.Item);
// Project selected attributes (tuple preserves types)
const recProj = await client.getItem('user', { hashKey2: 'h', rangeKey: 'r' }, [
'a',
] as const);
// Batch get
const many = await client.getItems('user', [
{ hashKey2: 'h', rangeKey: 'r1' },
{ hashKey2: 'h', rangeKey: 'r2' },
]);
const domain = client.entityManager.removeKeys('user', many.items);
Basic CRUD (records)
// Put a storage record (keys included)
await client.putItem({ hashKey2: 'h', rangeKey: 'r', a: 1 });
// Delete a record
await client.deleteItem({ hashKey2: 'h', rangeKey: 'r' });
Batched writes
// putItems
await client.putItems([
{ hashKey2: 'h', rangeKey: '1' },
{ hashKey2: 'h', rangeKey: '2' },
]);
// deleteItems
await client.deleteItems([
{ hashKey2: 'h', rangeKey: '1' },
{ hashKey2: 'h', rangeKey: '2' },
]);
Purge (scan + batched deletes)
const purged = await client.purgeItems();
// Keep specific records whatever the scan returns.
const purgedKeepingConfig = await client.purgeItems({
excludeKeys: [{ hashKey2: 'config', rangeKey: 'main' }],
});
From the CLI, the same option is --exclude-keys, repeatable, each value a JSON
key object or an array of them:
getdotenv dynamodb purge --force \
--exclude-keys '{"hashKey2":"config","rangeKey":"main"}' \
--exclude-keys '[{"hashKey2":"purge","rangeKey":"0"}]'
Transactions
await client.transactPutItems([
{ hashKey2: 'h', rangeKey: '10', x: 1 },
{ hashKey2: 'h', rangeKey: '11', x: 2 },
]);
await client.transactDeleteItems([
{ hashKey2: 'h', rangeKey: '10' },
{ hashKey2: 'h', rangeKey: '11' },
]);
Notes
entityManager.removeKeys(entityToken, records).Related