Socket
Book a DemoInstallSign in
Socket

fastify-dynamodb

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-dynamodb

Plugin to share a common DynamoDB DocumentClient configuration across Fastify

1.0.7
latest
Source
npmnpm
Version published
Weekly downloads
885
16.29%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

fastify

FAQs

Package last updated on 31 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.