# dynamodb-client

> Node / JS client for Dynamo DB

Latest version **1.0.6** (published 2018-03-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install dynamodb-client
pnpm add dynamodb-client
yarn add dynamodb-client
bun add dynamodb-client
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-03-10 |
| First published | 2018-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Tuqire hussain |
| Maintainers | tuqire |
| Keywords | dynamodb |

## Links

- npm: https://www.npmjs.com/package/dynamodb-client
- Repository: https://github.com/tuqire/dynamodb-client
- Homepage: https://github.com/tuqire/dynamodb-client#readme
- Issues: https://github.com/tuqire/dynamodb-client/issues
- npm.io page: https://npm.io/package/dynamodb-client

## Dependencies (1)

- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.202.0

## Recent versions

- 1.0.6 (latest) — 2018-03-10
- 1.0.5 — 2018-03-05
- 1.0.4 — 2018-03-04
- 1.0.3 — 2018-03-04
- 1.0.2 — 2018-03-04
- 1.0.1 — 2018-03-04
- 1.0.0 — 2018-03-04

## 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](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html)
3. `primaryKey`: The primary key of the table.

```js
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](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.03.html)
2. `parseDBItem(Item, schema)`: transform `Item` from DynamoDB API returned object into a traditional object in relation to the `schema` [read more](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.03.html)

```js
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
2. Convert more methods from DynamoDB SDK.
3. Register dynamoDB in a cleaner way.

## Contributors

* Tuqire Hussain <me@tuqire.com>

---
_Source: https://npm.io/package/dynamodb-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
