JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q47581F
  • License MIT

Node / JS client for Dynamo DB

Package Exports

  • dynamodb-client

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dynamodb-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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