Numerous Philanthropic Misanthropes

    @teleology/dynamo

    0.1.0 • Public • Published

    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 awsOptions to seed credentials, region and apiVersion for DynamoDB.DocumentClient. For concerned parties, the awsOptions are used in a pass-through fashion.

    import dynamo from '@teleology/dynamo';
    
    const exampleTable = dynamo({
      table: process.env.EXAMPLE_TABLE || 'Example',
      key: 'id',
      indexes: [
        {
          key: 'hid',
          name: 'HashGSI',
        },
      ],
    
      // (Optional) depending on environment
      awsOptions: {
        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[] || [];

    Changelog

    0.0.3

    • Fixed an issues related to updates

    0.0.1

    • Initial upload

    Install

    npm i @teleology/dynamo

    DownloadsWeekly Downloads

    6

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    17 kB

    Total Files

    13

    Last publish

    Collaborators

    • icarus-sullivan