ddbutil
v1.3.0
Published
Batch operations in AWS DynamoDB with DocumentClient interface
Downloads
66
Readme
DDButil
Helper functions for batch operations in AWS DynamoDB with DocumentClient
interface:
- run
query
/scan
operations without worrying aboutExclusiveStartKey
- run
batchPut
/batchDelete
(which usebatchWrite
operation internally) without worrying aboutUnprocessedItems
- utilise forwarding functions that call
.promise()
on docClient function results, so you don't have to
Installation
npm install ddbutil
Usage
query example
const docClient = new aws.DynamoDB.DocumentClient();
const queryParams = {
TableName: 'Table_A',
Select: 'SPECIFIC_ATTRIBUTES',
ProjectionExpression: 'Attr1, Attr2',
KeyConditionExpression: 'Attr1 = :Attr1',
ExpressionAttributeValues: { ':Attr1': '123' },
ReturnConsumedCapacity: 'TOTAL',
};
ddbutil.query(docClient, queryParams)
.then(items => {
console.log('Items found:', items.length);
return items;
});
batchPut example
const docClient = new aws.DynamoDB.DocumentClient();
const writeParams = {
ReturnConsumedCapacity: 'TOTAL',
};
const items = [
{ Attr1: '123', Attr2: 'aaa' },
{ Attr1: '123', Attr2: 'bbb' },
{ Attr1: '123', Attr2: 'ccc' },
];
ddbutil.batchPut(docClient, writeParams, 'Table_B', items)
.then(putResult => {
console.log('Put result:', putResult);
return putResult;
});