1.0.11 • Published 7 years ago

dynamodb-helper v1.0.11

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

dynamodb-helper

Installation

npm install dynamodb-helper

API

var dbHelper = require('dynamodb-helper')

dbHelper(docClient,tableName)

Create a new dbHelper object for the given docClient and tableName.

.find(queryHashKey, callback)

Get items by queryHashKey from the particular table and process callback function.

.putItem(item)

put item on the particular table

.list(callback)

Get all items from the particular table and process callback function.

Examples

Simple type negotiation

This simple example shows how to use dynamodb-helper to get items from dynamodb and upload items to dynamodb. First we have to require aws-sdk and then configure it by config.json like

{ 
    "accessKeyId": "AKIAJVsdfDSDSsA", 
    "secretAccessKey": "Dsy3GADSASDDFDFzwIx+HJY2jqvjq", 
    "region": "us-east-1" 
}

After that, we create the object of the DocumentClient of Dynamodb and inject it into dbHelper.

/*  Initialize   */
var AWS = require("aws-sdk");
AWS.config.loadFromPath('./config.json');
var docClient = new AWS.DynamoDB.DocumentClient({ apiVersion: '2012-08-10' });

var dbHelper = require('dynamodb-helper');
var Users = new dbHelper(docClient, 'Users');

/*  Find Data   */
Users.find(req.user.id, function (err,data) {
  console.log(data);
  if(err){
    console.log("Error occured");            
    return new Error(err);
  }
  //Do something

  })

/*  Upload Data   */
Users.putItem(  { 
                 id: req.user.id, 
                 devs:[
                        { 
                            sn: req.body.sn, 
                            name: req.body.name 
                        }
                      ] 
                });  

/*  Find all Data   */
Users.list(function(err,data){
  if (err){
    console.log(err);  
  }
  console.log(data);

});
1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago