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

aws-dynamo-helper

v1.0.5

Published

Library that makes it easy to work with AWS DynamoDB.

Downloads

1

Readme

aws-dynamo-helper

Helper library designed to reduce amount of code needed to work with DynamoDB.

Motivation

Working with DynamoDB has always been a pain. Even with new docClient from Amazon you still need quite a bit of code to perform simple operations. Lack of support for promises is another issue. I wanted to have a simple to use library that abstracted away a lot of boiler plate code.

Usage

DynamoDB Expressions

This library expects that you know how to write DynamoDB expressions. If you don't you can get familiar with them here. Many methods will expect to get expression name and value maps, if you are not familiar why here are some references: name maps and value maps.

All both attrbiutes will follow the same format in both cases.

Expression Example

const expression = ':name = #value1 AND :year = #value2';

Name Map - Example

const nameMap = { ':name' : 'firstName', ':year' : 'makeYear' };

Value Map - Example

const valueMap = { '#value1' : 'john', '#value2' : 1990 };

Constructor

const Dynamo = require('aws-dynamo-helper');
const db = new Dynamo(region, profile);
  • awsRegion - region in which your DynamoDB is located, default: process.env.AWS_DEFAULT_REGION. (optional)
  • profile - profile that will be used to get your AWS credentials. If none provided aws-sdk will follow its default chain to get credentials from your environment. (optional)

Methods

Library supports following operations.

get

db.get(tableName, hashAndRange)

Fetches record from DynamoDB.

  • tableName - name of the table (required)
  • hashAndRange - is an object that follows format: { hashName: 'hashValue', rangeName : 'rangeValue'}. If your table does not have range, ommit it. (required)

Example:

db.get('sampleTable', {
    patientId: '1',
    timestamp: 123456789
})

query

db.query(tableName, keyExpression, filterExpression, nameMap, valueMap)

Queries DynamoDB for a set of records that match specified pattern.

  • tableName - name of the table (required)
  • keyExpression - expression that will be used to filter your Key (hash and range) attributes. Query operation requires descrimination on key attributes (required)
  • filterExpression - expression that will be used to filter your non-Keys attributes (optional)
  • nameMap - attribute name map that will map attributes used in key and filter expressions to proper names (required)
  • valueMap - value map that will map values used in key and filter expressions to proper values (required)

Example:

db.query('sampleTable', ':name = #name', ':yr = #yr', { ':name' : 'firstName', ':yr' : 'makeYear'}, {'#yr' : 1990, '#name': 'john'}).
then((items) => {
    items.forEach((item) => console.log(item));
)}

update

db.update(tableName, hashAndRange, updateExp, expNames, expValues)

Updates a specific record in a table using update expression.

  • tableName - name of the table (required)
  • hashAndRange - is an object that follows format: { hashName: 'hashValue', rangeName : 'rangeValue'}. If your table does not have range, ommit it. (required)
  • updateExp - expression that will be used to update the record*(required)*
  • expNames - attribute name map that will map attributes used in update expression to proper names (required)
  • expValues - value map that will map values used in update expression to proper values (required)

Example:

db.update('sampleTable', { name: 'john' }, ':yr = #yr', { ':yr' : 'makeYear'}, {'#yr' : 1995}).
then(() => {
    console.log('success');
)}

delete

db.delete(tableName, hashAndRange, conditionExp, expNames, expValues)

Deletes a specific record or multiple records (that share same hash) in a table that match a conditional expression.

  • tableName - name of the table (required)
  • hashAndRange - is an object that follows format: { hashName: 'hashValue', rangeName : 'rangeValue'}. If your table does not have range or you want to delete multiple items that share the same hash, ommit it. (required)
  • conditionExp - expression that will be used to verify that record qualifies for deletion*(optional)*
  • expNames - attribute name map that will map attributes used in condition expression to proper names (optional)
  • expValues - value map that will map values used in condition expression to proper values (optional)

Example:

db.delete('sampleTable', { name: 'john' }, ':yr > #yr', { ':yr' : 'makeYear'}, {'#yr' : 1995}).
then((items) => {
    items.forEach((item) => console.log(`item deleted: ${item}`));
)}

store

db.get(tableName, recordObj)

Stores a single item into a table.

  • tableName - name of the table (required)
  • recordObject - object that you want to store, it must have proper hash and range keys set. (required)

Example:

db.store('sampleTable', {
    name: 'john',
    makeYear: 1989,
    taste: 'crappy'
})

Conlusion

I hope this library is helpful! For any questions or comments feel free to reach out to me via GitHub @glaciannex.