when-dynamodb

A promise wrapper for the NodeJS dynamodb library

npm install when-dynamodb
14 downloads in the last week
27 downloads in the last month

WhenDynamoDB

A promise wrapper for the NodeJS dynamodb library which uses the when promise library.

Most of the functions are named the same thing and require input/output in the same format as the dynamodb library. Click on the link above for more information about them. The main difference is that instead of expecting a callback as the last parameter, the function will return a promise which can then have .then(callback) called on it.

However, there are a few helper functions that are original to this library, specified below.

Basic Example

WhenDynamoDB = require('when-dynamodb');
DB = new WhenDynamoDB({id: AWS_KEY_ID, key: AWS_SECRET_ACCESS_KEY});

user = {
  email: 'john_smith@example.com',
  name: 'John Smith'
};

options = {};

DB.putItem('Users', user, options)
.then(function(response){
  console.log("Successfully put user");
  console.log(response);
})
.otherwise(function(error){
  console.log("There was an error");
  console.log(error);
})
.done();

New Functions

There are several functions that the dynamodb library does not provide but which can be rather useful. They are as follows:
function operateOnItems(tableName, hashKey, operation, options){}
function operateOnAllItems(tableName, operation, options){}
function deleteItems(tableName, hashKey, verified){}
function deleteAllItems(tableName, verified){}

operateOnItems

This is a function meant for tables that have both a hash key and a range key. Given a hash key, this will run a callback function called operation on all elements with that hash key. The utility of this function is that it will do so even if it is necessary to run multiple requests due to the number of items with the given hash key. This function has the potential to make many DynamoDB calls (depending on the number of items) and should therefore be used with care.

operateOnAllItems

This function is similar to the one above with the exception that it doesn't ask for even a hash key. It will operate on absolutely all items in the table. Use with care.

deleteItems

This function passes its parameters to the operateOnItems function and deletes all returned elements. Use with care.

deleteAllItems

This function will delete every element of the given table. As a result, it's required to pass in the table's name as a first and second parameter to verify that you actually want to delete all the elements in that table. Use with extreme care.

npm loves you