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-client

v1.0.6

Published

Node / JS client for Dynamo DB

Downloads

44

Readme

DynamoDB Client

A lightweight JS / Node DynamoDB client which uses the AWS SDK, but abstracts out some of its complexities. Also replaces callbacks with promises.

NOTE: This lib is still in it's early stages. Only a few of the DynamoDB methods have been abstracted out. All the original methods are available on the this.DynamoDB attribute.

How it Works

The DynamoTable class takes the following data on initialisation:

  1. tableName: The table name.
  2. schema: Schema according to DynamoDB requirements. read more
  3. primaryKey: The primary key of the table.
import { setAwsConfig, DynamoTable } from 'dynamodb-client'

setAwsConfig({
  accessKeyId,
  secretAccessKey,
  region
})

const myTable = new DynamoTable({
  tableName: 'MyTable',
  schema: {
    myPrimaryKey: 'S',
    myString: 'S',
    myStringSet: 'SS',
    map: {
      type: 'M',
      schema: {
        mySubString: 'S',
        mySubBoolean: 'B'
      }
    }
  },
  primaryKey: 'myPrimaryKey'
})

const testLib = async () => {
  const itemId = 'someId'

  await myTable.add({
    myPrimaryKey: itemId,
    myString: 'val',
    myStringSet: ['val1', 'val2', 'val3']
  })

  await myTable.get(itemId)

  await myTable.update(itemId, {
    myString: 'newVal',
    myStringSet: ['newVal1']
  })

  await myTable.delete(itemId)
}

The library also exports two methods which help in the construction and deconstruction of traditional JS objects into DynamoDB valid object.

  1. buildDBItem(item, schema): converts item into an object which is understood by DynamoDB API in relation to the schema read more
  2. parseDBItem(Item, schema): transform Item from DynamoDB API returned object into a traditional object in relation to the schema read more
import { buildDBItem, parseDBItem } from 'dynamodb-client'

const schema = {
  myString: 'S',
  myBool: 'B',
  myStringSet: 'SS',
  myMap: {
    type: 'M',
    schema: {
      subString: 'S'
    }
  }
}

const item = {
  myString: 'foo'
  myBool: false,
  myStringSet: ['str', 'str2', 'str3'],
  myMap: {
    subString: 'bar'
  }
}

const transformedItem = buildDBItem(item, schema)

/**
transformedItem === {
  myString: { S: 'string' },
  myBool: { B: false },
  myStringSet: { SS: ['str', 'str2', 'str3'] },
  myMap: {
    M: {
      subString: { S: 'string' }
    }
  }
}
**/

const convertedItem = parseDBItem(transformedItem, schema)

/**
convertedItem === item
**/

Todo

  1. Add unit tests.
  2. convert item vals which are numbers to string automatically
  3. Convert more methods from DynamoDB SDK.
  4. Register dynamoDB in a cleaner way.

Contributors