1.13.4 • Published 6 years ago

@dotconnor/ddb v1.13.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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);
 });
1.13.4

6 years ago

1.13.3

6 years ago

1.13.1

6 years ago

1.13.0

6 years ago

1.12.0

6 years ago

1.11.0

6 years ago

1.10.0

6 years ago

1.9.1

6 years ago

1.9.0

6 years ago

1.8.0

6 years ago

1.7.1

6 years ago

1.7.0

6 years ago

1.6.6

7 years ago

1.6.5

7 years ago

1.6.4

7 years ago

1.6.3

7 years ago

1.6.2

7 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago