# fastify-dynamodb

> Plugin to share a common DynamoDB DocumentClient configuration across Fastify

Latest version **1.0.7** (published 2019-10-31) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2019-10-31 |
| First published | 2018-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 3 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 (+10 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Bogusz Przybyslawski |
| Maintainers | matrus2 |
| Keywords | fastify, dynamodb, nosql, aws |

## Links

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

## Dependencies (3)

- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.475.0
- [fastify](https://npm.io/package/fastify.md) ^0.39.1
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^0.2.2

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.7 (latest) — 2019-10-31
- 1.0.6 — 2019-07-11
- 1.0.5 — 2019-06-14
- 1.0.4 — 2018-05-09
- 1.0.3 — 2018-05-09
- 1.0.2 — 2018-01-16
- 1.0.1 — 2018-01-16
- 1.0.0 — 2018-01-16

## README

# fastify-dynamoDB

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)
[![Build Status](https://travis-ci.org/matrus2/fastify-dynamodb.svg?branch=master)](https://travis-ci.org/matrus2/fastify-dynamodb) 

This plugin shares [AWS.DynamoDB.DocumentClient()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html) object, so you can easy use DynamoBD with fastify.

## Install
```
npm i fastify-dynamodb -S
```
## Usage
Add it to you project with `register` and you are done!  
You can access the *DynamoDB DocumentClient* via `fastify.dynamo`.
```js
const fastify = require('fastify')

fastify.register(require('fastify-dynamodb'), {
    endpoint: 'http://localhost:8000',
    region: AWS_REGION
  })

fastify.listen(3000, err => {
  if (err) throw err
  console.log(`server listening on ${fastify.server.address().port}`)
})
```

In your route file you can simply do all gets, queries, scans e.g.:

```js
async function singleRoute(fastify, options) {
  fastify.get(
    '/users/:id',
    async (request, reply) => {
      let data
      const { id } = request.params;
      const params = {
        TableName: TABLE_NAME,
        Key: {
          user_id: id
        },
      };
      try {
        data = await fastify.dynamo.get(params).promise();
      } catch (e) {
         reply.send(e)
      }
      return { data }
    },
  )
}
```

## License

Licensed under [MIT](./LICENSE).

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