New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@dotconnor/ddb

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotconnor/ddb

A DynamoDB Wrapper

latest
Source
npmnpm
Version
1.13.4
Version published
Maintainers
1
Created
Source

@dotconnor/ddb

A DynamoDB Wrapper

Install

To install first run this command in your project's main folder:

npm install @dotconnor/ddb --save

Then in your project include this at the top:

const ddb = require("@dotconnor/ddb");

Initialization

Initializing ddb is very easy. If AWS Credentials are already on file then all you need to do is:

const db = new ddb();

For a profile other than default:

const db = new ddb({profile: "work"});

Or can you include your Access Key ID and Secret Access Key:

const db = new ddb({
    accessKeyId: "...",
    secretAccessKey: "...",
    region: "us-west-2" //Defaults to us-east-1
});

Scanning A Table

ddb provides the scanBuilder class to help scan a table.

var scan = db.scan("TableName");
/*
scan = { 
    params: { 
        TableName: 'TableName', 
        FilterExpression: '' 
    },
    _db: [Object] 
}
*/

This returns a scanBuilder the the following methods:
addFilter(name, value, op)

scan = scan.addFilter("id", 123, "=");
/*
scan = {
    params: {
        TableName:"TableName",
        FilterExpression:"id = :id",
        ExpressionAttributeValues:{
            ":id":{
                "N":"123"
            }
        }
    },
    _db: [Object] 
}
*/

Get The Results

Calling the execute() method on the scanBuilder will return a Promise containing the items matching the given filters.

scan
.execute()
.then(function(data) {
    console.log(data); //Array of items found. [] If none were found.
}).catch(function(err){
    console.log(err):
});

Updating An Item

(WIP)

ddb provides the updateBuilder class to help update an item.

var update = db.update("TableName");

Set the key name and its value of the item that need to be updated.

update.setKey("uuid", "a7d6as-528ad-1471");

Add the key and their values that need to be updated.

update.updateItem("email", "connor@dotconnor.com");

Increment an item:

update.incrementItem("karma", 1);

Update the selected item(s)

update.execute()
.then(function(data) {
    console.log(data); // data should be = []
}).catch(function(err){
    console.log(err):
});

Put Item

putItem(TableName, Item)

db.putItem("Users", {
  id: "1452a",
  username: "dotconnor",
}).then(function(){
  console.log("User Created");
});

Generate An ID

generateId(TableName, ItemName, Type, opts)

db.generateId("Users", "uuid", "uuid")
.then(function(id){
    console.log(id);
 });

FAQs

Package last updated on 27 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts