0.2.1 • Published 3 years ago

@teleology/dynamo v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Downloads Version License

@teleology/dynamo

A configurable client wrapper around DynamoDB.DocumentClient

Installation

yarn add aws-sdk @teleology/dynamo
# or
npm i --save aws-sdk @teleology/dynamo

Configuration

Configuration is easy and mimics much of the pre-defined attributes of the DynamoDB table such as a table name, primary key, and secondary indexes. The library is aimed to be used within an AWS lambda context, if you are not within an environment that automatically handles this for you. You can pass the optional options to seed credentials, region and apiVersion for DynamoDB.DocumentClient. For concerned parties, the options are used in a pass-through fashion.

import dynamo from '@teleology/dynamo';

const exampleTable = dynamo({
  table: process.env.EXAMPLE_TABLE || 'Example',

  // (Optional) depending on environment
  options: {
    accessKeyId: 'your_access_key_id', 
    secretAccessKey: 'your_secret_access_key',
    region: 'us-east-1',
  }
});

Usage

const exampleTable = ... // configuration example

const record = await exampleTable.create({
  id: '123',
  fName: 'Luke',
});

const updated = await exampleTable.update({
  id: '123',
  fName: 'Lucas',
  lName: 'Smith',
  hid: 'secondary-id',
});

const ping = await exampleTable.get('123');

const items = await exampleTable.query({ hid: 'secondary-id' });

await exampleTable.delete('123');

Get

async table.get(primaryKey: String) => Record || undefined

Create

async table.create(record: Object) => Record || Error

Update

async table.update(record: Object) => Record || Error

Delete

async table.delete(primaryKey: String)

Query

async table.query(globalSecondaryKeyVal: Object) => Record[] || [];

Batch Put

async table.batchPut(items ...Object);

Batch Delete

async table.batchDelete(primaryKeys ...String);

Batch Get

async table.batchGet(primaryKeys ...String) => Items[];

Changelog

0.2.1

  • Adding query operation to delete function for GSI

0.1.1

  • Adding ability to query on multiple GSI's instead of one

0.0.3

  • Fixed an issues related to updates

0.0.1

  • Initial upload
0.2.1

3 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.4

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago