npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-ddb

v1.0.9

Published

The simple way to interact with AWS dynamodb

Downloads

3

Readme

Easy Dynamo DB

The idiot-proof way to interact with AWS DynamoDB from JS/TS

Overview

Easy Dynamo was made so that you don't have to think about the AWS wrappers when dealing with DynamoDB at all. All interactions will give you JSON objects that look the way they did in your code when they were added to dynamo, so you can move data back and forth to dynamo effortlessly.

Getting Started

Install

npm install easy-ddb

Example

For simplicity, here's example code and output so you can start building right away (see ./examples/example.js for the runnable example)

Code

const EasyDynamo = require("easy-ddb");

// Assume the keys to MyTable are
// Hash key: myHashKey of type string
// Range key: myRangeKey of type string
const tableName = "MyTable";

const dynamo = new EasyDynamo({
  accessKeyId: "Enter yours here",
  secretAccessKey: "Enter yours here",
  region: "Enter yours here",
  // Uncomment endpoint if you are testing with the local dynamodb server
  // endpoint: "http://localhost:8000",
});

(async () => {
  const keys = { myHashKey: "abc", myRangeKey: "def" };
  const myItem1 = {
    myHashKey: "abc",
    myRangeKey: "def",
    myNum: 1,
    myList: ["foo", "bar"],
    myNested: { nestedString: "abc", nestedNum: 2 },
  };
  await dynamo.put({ item: myItem1, tableName });
  console.log("After put myItem1", await dynamo.get({ keys, tableName }));

  const myItem2 = {
    myHashKey: "abc",
    myRangeKey: "woah",
    isFriend: true,
  };
  await dynamo.put({ item: myItem2, tableName });
  console.log(
    "Query after put of myItem2",
    await dynamo.query({
      keyName: "myHashKey",
      value: "abc",
      tableName,
    })
  );

  await dynamo.update({
    keys,
    propsToUpdate: { myNum: 3, poptartType: "Smores" },
    tableName,
  });
  console.log(
    "Get myItem1 after update",
    await dynamo.get({ keys, tableName })
  );
  await dynamo.incrementValue({ keys, attrNames: ["myNum"], tableName });
  console.log(
    "Get myItem1 after increment attribute",
    await dynamo.get({ keys, tableName })
  );

  await dynamo.incrementValue({
    keys,
    attrNames: ["myNested", "nestedNum"],
    tableName,
  });
  console.log(
    "Get myItem1 after increment nested attribute",
    await dynamo.get({ keys, tableName })
  );

  const gotItemAfterIncr = await dynamo.get({ keys, tableName });
  console.log("Get myItem1 after increment nested attribute", gotItemAfterIncr);
})();

Output

After put myItem1 {
  myHashKey: 'abc',
  myNum: 1,
  myNested: { nestedNum: 2, nestedString: 'abc' },
  myRangeKey: 'def',
  myList: [ 'bar', 'foo' ]
}
Query after put of myItem2 [
  {
    myHashKey: 'abc',
    myNum: 1,
    myNested: { nestedNum: 2, nestedString: 'abc' },
    myRangeKey: 'def',
    myList: [ 'bar', 'foo' ]
  },
  { myHashKey: 'abc', myRangeKey: 'woah', isFriend: true }
]
Get myItem1 after update {
  myHashKey: 'abc',
  myNested: { nestedNum: 2, nestedString: 'abc' },
  myNum: 3,
  myRangeKey: 'def',
  poptartType: 'Smores',
  myList: [ 'bar', 'foo' ]
}
Get myItem1 after increment attribute {
  myHashKey: 'abc',
  myNested: { nestedNum: 2, nestedString: 'abc' },
  myNum: 4,
  myRangeKey: 'def',
  poptartType: 'Smores',
  myList: [ 'bar', 'foo' ]
}
Get myItem1 after increment nested attribute {
  myHashKey: 'abc',
  myNested: { nestedNum: 3, nestedString: 'abc' },
  myNum: 4,
  myRangeKey: 'def',
  poptartType: 'Smores',
  myList: [ 'bar', 'foo' ]
}
Get myItem1 after increment nested attribute {
  myHashKey: 'abc',
  myNested: { nestedNum: 3, nestedString: 'abc' },
  myNum: 4,
  myRangeKey: 'def',
  poptartType: 'Smores',
  myList: [ 'bar', 'foo' ]
}

Functions

put: Add an item to a dynamo table
get: Get an item from a dynamo table
delete: Delete an item from a dynamo table
update: Update an item in a dynamo table (adding the item if it does not yet exist)
query: Query a dynamo table
queryOnSecondaryIndex: Query a dynamo table on its secondary index
scan: Scan a dynamo table
clearTable: Clear a dynamo table
updateAddToSet: Add element to a set in a dynamo table
updateDeleteFromSet: Delete element from a set in a dynamo table
incrementValue: Increment the value of a particular attribute of a particular entry
decrementValue: Decrement the value of a particular attribute of a particular entry.

Quick pointers

  • Look at the example, it should make everything obvious
  • All functions are async
  • For write operations (put, update, updateAddToSet, incrementValue, etc.), the return type is promise resolving to void unless an error occurs, in which case the promise will reject with that error
  • For read operations (get, query, scan, queryOnSecondaryIndex, etc.), the return type is promise resolving to the item (or null if item is not found), a list of items, a count of the items (if onlyCount is true) unless an error occurs, in which case the promise will reject with that error