npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

egg-dynamodb

v1.0.0

Published

dynamodb plugin for egg.js.

Downloads

5

Readme

egg-dynamodb

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Dynamodb plugin for Eggjs.

Install

$ npm i egg-dynamodb --save

Example

We can easily get the description of a table like below:

  const params = {
    TableName: "test_table",
  };
  const tableDescription = await app.dynamodb.client.describeTable(params);

We can also put an item into a table like this:

  const param = {
    TableName : 'test_table',
    Item: {
      HashKey: 'haskey',
      NumAttribute: 1,
    }
  };

  await app.dynamodb.put(param);

As you can see, app.dynamodb is the DynamoDB DocumentClient and app.dynamodb.client is the DynamoDB low level client.

Configuration

Enable plugin:

// {app_root}/config/plugin.js
exports.dynamodb = {
  enable: true,
  package: 'egg-dynamodb',
};

Additionally, egg-dynamodb depend on egg-aws-sdk, so we must add the following config:

// {app_root}/config/plugin.js
exports.awsSdk = {
  enable: true,
  package: 'egg-aws-sdk',
};

and don't forget to install the egg-aws-sdk as a dependency:

$ npm i egg-aws-sdk --save

Configure the dynamodb client:

// {app_root}/config/config.default.js
exports.dynamodb = {
  client: {
    endpoint: '',
    region: '',
    accessKeyId: '',
    secretAccessKey: '',
  },
  // or multi clients
  // clients: {
  //   dynamodb1: {
  //     endpoint: '',
  //     region: '',
  //     accessKeyId: '',
  //     secretAccessKey: '',
  //   },
  //   dynamodb2: {
  //     endpoint: '',
  //     region: '',
  //     accessKeyId: '',
  //     secretAccessKey: '',
  //   },
  // },
};

Usage

Single Client

You can use app.dynamodb to get the dynamodb instance.

// app/controller/home.js

module.exports = app => {
  return class HomeController extends app.Controller {
    async index() {
      const { ctx, app } = this;
      const param = {
        TableName : 'test_table',
        Item: {
          HashKey: 'haskey',
          NumAttribute: 1,
        }
      };
      await app.dynamodb.put(param);
    }
  };
};

Multi Clients

If your Configure with multi clients, you can use app.dynamodb.get('instanceName') to get the specific dynamodb instance and use it like above.

// app/controller/home.js

module.exports = app => {
  return class HomeController extends app.Controller {
    async index() {
      const { ctx, app } = this;
      const param = {
        TableName : 'test_table',
        Item: {
          HashKey: 'haskey',
          NumAttribute: 1,
        }
      };
      await app.dynamodb.get('instance1').put(param);
    }
  };
};

API

The original aws interface does not provide the straight promise support, we must invoke the .promise() to get the promise object. It is not very convenient to use. In order to simplify the usage, egg-dynamodb wrap all the interface making them auto return the promise object which means we can directly await any function.

DynamoDB Client

DynamoDB DocumentClient

Questions & Suggestions

Please open an issue here.

License

MIT