This is a tiny module that eases calls to DynamoDB. It includes only the most frequently-used calls I make, along with configuration I often use. Could be useful for someone else, but I'm hosting it here for easier installation and updates between projects. :)
const DynamoHelper = require('dynamo-helper');
DynamoHelper.scan(...);
DynamoHelper.add(...);
DynamoHelper.get(...);
DynamoHelper.delete(...);
npm install dynamo-helper
Calls update
for an item. It crafts the UpdateStatement
based on the keys and values of the object
parameter.
Parameters:
-
tableName
(String) -
idProperty
(String) - The name of the hash field. -
idValue
(String) - The actual value of the id. -
object
(Map) - The object to insert or update.
Returns:
Promise(item)
- A promise which will resolve with the added item, or an error if one occurred.
Scans a given table. Optionally accepts an index name and filters. Currently does not support paging.
Parameters:
-
tableName
(String) -
indexName
(String, optional) - A secondary index to use. -
filters
(Map, optional) - The filters to be added toFilterExpression
andExpressionAttributeValues
. -
projection
(String, optional) - AProjectionExpression
to filter result columns.
Returns:
Promise({
items: [...],
count:
})
The items are an array of scanned rows (which may be filtered). The count
represents the TotalCount.
Get by id.
Parameters:
-
tableName
(String) -
idProperty
(String) - The name of the hash field. -
idValue
(String) - The actual value of the id.
Returns:
Promise(item)
- A promise which will resolve with the item or null
(if none was found).
Delete by id.
Parameters:
-
tableName
(String) -
idProperty
(String) - The name of the hash field. -
idValue
(String) - The actual value of the id.
Returns:
Promise(item)
- A promise which will resolve with the deleted item.