dynamodb-table-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

dynamodb-table-client

A DocumentClient wrapper for single table design and better typescript support.

For the most part, the API is the same as DocumentClient aside from having to provide the TableName for each request. batchGet and batchWrite have a slightly different API because they don't need to be concerned with multiple tables.

Install

npm install dynamodb-table-client

Usage

import { TableClient } from 'dynamodb-table-client';

// common attributes between all items
interface DynamoDBItem {
  // this is where you would type your Key and GSI schemas
  PK: string;
  SK: string;
  GSI1PK?: string;
  GSI1SK?: string;

  // but you could use it for common meta atts as well
  created: string;
}

const tableClient = new TableClient<DynamoDBItem>({
  tableName: `my-table`,
  region: `us-east-1`,
});

interface Note extends DynamoDBItem {
  title: string;
}

await tableClient.put<Note>({
  Item: {
    PK: 'NOTE#1',
    SK: 'META',
    created: new Date().toISOString(),
    title: 'My Note',
  },
});

const note = await tableClient.get<Note>({
  Key: {
    PK: 'NOTE#1',
    SK: 'META',
  },
});

Readme

Keywords

none

Package Sidebar

Install

npm i dynamodb-table-client

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

258 kB

Total Files

12

Last publish

Collaborators

  • mattjennings