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

dynamodb-simple

v0.1.2

Published

A simple and elegant interface for aws-sdk dynamodb documentClient

Downloads

3

Readme

dynamodb-simple

A simple and elegant interface for aws-sdk dynamodb documentClient

Quick Links:

Usage

You can reference aws DocumentClient documentation to get a better understanding of how these methods work under the hood

config

setup aws config You can skip this step if you already have credentials setup for aws-sdk

const dynamodbSimple = require('dynamodb-simple');

dynamodbSimple.config({
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  region: process.env.AWS_REGION,
  endpoint: process.env.DYNAMODB_ENDPOINT
});

table

Create a table instance;

const dynamodbSimple = require('dynamodb-simple');

// with just hash
// table name, hash name, range name
const userTable = dynamodbSimple.table('user', 'id');

// with hash and range
const userTable = dynamodbSimple.table('user', 'id', 'age');

scan

FilterExpression queries FilterExpression Documentation

const dynamodbSimple = require('dynamodb-simple');
const userTable = dynamodbSimple.table('user', 'id');
const userId = 1; // hash
const name = 'Ben';
const age = '30';

// scan using single attr
userTable.scan(`id = '${userId}'`, (err, doc) => {
  if (err) return console.log(err);
  console.log(doc);
});

// scan using multiple attr
userTable.scan(`name = '${name}' AND age = ${age}`, (err, doc) => {
  if (err) return console.log(err);
  console.log(doc);
});

query

Query using hash and range to find data. You can configure a table to use just hash or both hash and range Write KeyConditionExpression queries KeyConditionExpression Documentation

const dynamodbSimple = require('dynamodb-simple');
const userId = 1; // hash
const age = '30'; // range
const name = 'ben';

// query using just hash. This is dependent on how your table is configured
const userTable = dynamodbSimple.table('user', 'id');
dynamodbSimple.scan(`id = '${userId}'`, (err, doc) => {
  if (err) return console.log(err);
  console.log(doc);
});

// query using hash and range. This is dependent on how your table is configured
const userTableWithRange = dynamodbSimple.table('user', 'id', 'age');
userTableWithRange.scan(`id = '${userId}' AND age = ${age}`, (err, doc) => {
  if (err) return console.log(err);
  console.log(doc);
});

// query using hash and range with other attributes. This is dependent on how your table is configured
userTableWithRange.scan(`id = '${userId}' AND age = ${age} AND name = '${name}'`, (err, doc) => {
  if (err) return console.log(err);
  console.log(doc);
});

get

Get using hash and range to find data. You can configure a table to use just hash or both hash and range

const dynamodbSimple = require('dynamodb-simple');
const userId = 1; // hash
const age = '30'; // range

// get using just hash. This is dependent on how your table is configured
const userTable = dynamodbSimple.table('user', 'id');
userTable.get(userId, (err, doc) => {
  if (err) return console.log(err);
  console.log(doc);
});

// get using hash and range. This is dependent on how your table is configured
const userTableWithRange = dynamodbSimple.table('user', 'id', 'age');
userTableWithRange.get(userId, age, (err, doc) => {
  if (err) return console.log(err);
  console.log(doc);
});

put

Put data

const dynamodbSimple = require('dynamodb-simple');
const userTable = dynamodbSimple.table('user', 'id');

// get using just hash. This is dependent on how your table is configured
let newUser = {
  name: 'ben',
  age: 30
};
userTable.put(newUser, err => {
  if (err) return console.log(err);
});

update

Put data

const dynamodbSimple = require('dynamodb-simple');
const userTable = dynamodbSimple.table('user', 'id');
const userId = 1; // hash
const newName = 'Colton';
const bestFriend = 'Rich';

// update 1 property
userTable.update(`SET name = '${newName}'`, userId, err => {
  if (err) return console.log(err);
});

// update multiple properties
userTable.update(`SET name = '${newName}', bestFriend = '${bestFriend}', employee = true`, userId, err => {
  if (err) return console.log(err);
});

delete

Delete data

const dynamodbSimple = require('dynamodb-simple');
const userId = 1;
const age = 30;

// get using just hash. This is dependent on how your table is configured
const userTable = dynamodbSimple.table('user', 'id');
userTable.delete(userId, (err, doc) => {
  if (err) return console.log(err);
  console.log(doc);
});

// get using hash and range. This is dependent on how your table is configured
const userTableWithRange = dynamodbSimple.table('user', 'id', 'range');
userTableWithRange.delete(userId, age, (err, doc) => {
  if (err) return console.log(err);
  console.log(doc);
});

createTable

Create Table

const dynamodbSimple = require('dynamodb-simple');

dynamodbSimple.createTable('tablename', 'hahskey', 'optionalRangeKey', (err, tableInfo) => {
  if (err) return console.log(err);
  console.log(tableInfo);
});

deleteTable

Delete table

const dynamodbSimple = require('dynamodb-simple');

dynamodbSimple.createTable('tablename', (err, tableInfo) => {
  if (err) return console.log(err);
  console.log(tableInfo);
});

listTables

List data

const dynamodbSimple = require('dynamodb-simple');

dynamodbSimple.listTabled((err, tables) => {
  if (err) return console.log(err);
  console.log(tables);
});

describeTable

List data

const dynamodbSimple = require('dynamodb-simple');

dynamodbSimple.describeTabled('tableName', (err, tableInfo) => {
  if (err) return console.log(err);
  console.log(tableInfo);
});