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

simp-ddb

v1.2.10

Published

A simple DynamoDB wrapper module. Targeted for people who are just want to do simple stuff, in a simple way on DynamoDB.

Downloads

55

Readme

About SimpDDB

Main Features

  • Intended so a JavaScript caveperson can use it - A little bit of JSON "know how" is all you need
  • Intended for a very basic set of DynamoDB operations
    • get - key + sort will return one object
    • put - will overwrite the item with a new item
    • del - will delete the item. key + sort is required, any other attributes are ignored and will not affect the operation
    • query - uses key condition experession "begins_with", key + sort is required, any other attributes are ignored and will not affect the operation.
    • batch - processes in batches of 25, if a batch fails only the requests in that batch group fail.
  • Extends DynamoDB Client - AWS SDK for JavaScript v3
  • Lightweight
  • Intended to bring a smile

Other info

  • All ddb tables must have "key" and "sort" as the composite key.
  • All item attributes are inserted as strings into ddb by default, but, can be overwritten to store them as intended.
  • undefined or "undefined" is stored as an empty string.
  • null is stored as an empty string
  • Currently no other DynamoDB features are supported.

How to use SimpDDB

Require it

const SimpDDB = require("simp-ddb");

Gotta have these

const TableName = "YOUR_TABLE_NAME";
const region = "us-east-1";

Credentials and Region

const ACCESS_KEY = "ASIA52IMGHBLAHBLAHBLAH";
const SECRET_ACCESS_KEY = "SqnqvvJRq+5asEyudgSv6+BLAHBLAHBLAH";
const SESSION_TOKEN = "IQoJb3JpZ2luX2VjEAYaCXVzLWVhc3QtMSJGMEQCIDslP8DeavFrEMddVERYLONGBLAHBLAHBLAH";

const clientParams = {
  "region": region,
  "credentials": {
     "accessKeyId": ACCESS_KEY,
     "secretAccessKey": SECRET_ACCESS_KEY,
     "sessionToken": SESSION_TOKEN
  }
};

const simpDDB = new SimpDDB(clientParams);

Settings

Currently storeAsStrings is the only setting available. But, if any others are added, you'll find it here.

  //By default, SimpDDB stores all item attributes as strings. To store as primitive and object values, set the following command set to false.
  simpDDB.settings({
    "storeAsStrings": false
  });
  //If set to true it will store as strings again.
  simpDDB.settings({
    "storeAsStrings": true
  });

Example put operation

(async function (){
  //put will override existing items. If you want to remove an attribute from an item use put
  await simpDDB.snd({
    "send":"put",
    "TableName":TableName,
    "key":"test",
    "sort":"test0",
    "anotherAttr":"anotherValues",
    "anotherAttrAdded":"anotherValuesAdded",
    "zeroNum":0,
    "zeroStr":"0",
    "trueBool":true,
    "trueStr":"true",
    "falseBool":false,
    "falseStr":"false",
    "object":{"one":1,"bool":false},
    "objectStr":"{\"one\":1,\"bool\":false}",
    "dateIso": new Date().toISOString(),
    "undefinedVal":undefined,
    "undefinedStr":"undefined",
    "nullVal": null
  })
  .then((data)=>{
    console.log(data);
  })
  .catch((err)=>{
    console.log(err);
  });
})();

Example upd operation

(async function (){
  // upd will create or update existing items. It will add new attributes or 
  // change the value of existing attributes, but, it will not delete attributes
  await simpDDB.snd({
    "send":"upd",
    "TableName":TableName,
    "key":"test",
    "sort":"test1",
    "anotherAttr":"anotherValues",
    "anotherAttrAdded":"anotherValuesAdded",
    "zeroNum":0,
    "zeroStr":"0",
    "trueBool":true,
    "trueStr":"true",
    "falseBool":false,
    "falseStr":"false",
    "object":{"one":1,"bool":false},
    "objectStr":"{\"one\":1,\"bool\":false}",
    "dateIso": new Date().toISOString(),
    "undefinedVal":undefined,
    "undefinedStr":"undefined",
    "nullVal": null
  })
  .then((data)=>{
    console.log(data);
  })
  .catch((err)=>{
    console.log(err);
  });
})();

Example get operation

(async function (){
  // get will return one item 
  await simpDDB.snd({
    "send":"get",
    "TableName":TableName,
    "key":"test",
    "sort":"test0",
    "consistent": true //supported by query and get operations
  })
  .then((data)=>{
    console.log(data);
  })
  .catch((err)=>{
    console.log(err);
  });
})();

Example query operation

(async function (){
  //query will return an array of items
  await simpDDB.snd({
    "send":"query",
    "TableName":TableName,
    "key":"test",
    "sort":"test",
    "condition":"begins_with",
    "consistent": true //supported by query and get operations
  })
  .then((data)=>{
    console.log(data);
  })
  .catch((err)=>{
    console.log(err);
  });
})();

Example del operation

(async function (){
  //query will return an array of items
  await simpDDB.snd({
    "send":"del",
    "TableName":TableName,
    "key":"test",
    "sort":"test0"
  })
  .then((data)=>{
    console.log(data);
  })
  .catch((err)=>{
    console.log(err);
  });
})();

Example for: "batch" operation

batchAction only supports "del", "put" operations

(async function (){
 //batch put or del
 //batchAction only supports "del", "put" operations
 //batches are processed in batch groups of 25
 const arrList = [
   {
     "batchAction":"put",
     "key":"test",
     "sort":"test2",
     "anotherAttr":"anotherValues",
     "anotherAttrAdded":"anotherValuesAdded",
     "zeroNum":0,
     "zeroStr":"0",
     "trueBool":true,
     "trueStr":"true",
     "falseBool":false,
     "falseStr":"false",
     "object":{"one":1,"bool":false},
     "objectStr":"{\"one\":1,\"bool\":false}",
     "dateIso": new Date().toISOString(),
     "undefinedVal":undefined,
     "undefinedStr":"undefined",
     "nullVal": null
   },
   {
     "batchAction":"del",
     "key":"test",
     "sort":"test1"
   }
 ];
 await simpDDB.snd({
   "send":"batch",
   "TableName":TableName,
   "batchList": arrList
 });
})();