1.0.7 • Published 5 years ago

fastify-dynamodb v1.0.7

Weekly downloads
17
License
MIT
Repository
github
Last release
5 years ago

fastify-dynamoDB

js-standard-style Build Status

This plugin shares AWS.DynamoDB.DocumentClient() 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.

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.:

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.

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago