egg-tablestore

2.0.2 • Public • Published

egg-tablestore

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

Install

$ npm i egg-tablestore --save

Usage

// {app_root}/config/plugin.js
exports.TableStore = {
  enable: true,
  package: 'egg-tablestore',
};
 
await app.tabestore.putRow(params);
//or
await ctx.tabestore.putRow(params);
//If you want to access TableStore module, you can:
app.TableStore
app.TableStore.Long

Configuration

Simple database instance

exports.tablestore = {
  // database configuration
  client: {
    accessKeyId: '<your access key id>',
    secretAccessKey: '<your access key secret>',
    stsToken: '<your stsToken>', /*When you use the STS authorization, you need to fill in. ref:https://help.aliyun.com/document_detail/27364.html*/
    endpoint: '<your endpoint>',
    instancename: '<your instance name>'
  },
  // load into app, default is open
  app: true,
  // load into agent, default is close
  agent: false,
};

Usage:

await app.tabestore.putRow(params);
//or
yield app.tabestore.putRow(params);

Multiple database instance

exports.tablestore = {
  clients: {
    // clientId, access the client instance by app.tablestore.get('clientId')
    db1: {
      accessKeyId: '<your access key id>',
      secretAccessKey: '<your access key secret>',
      stsToken: '<your stsToken>', /*When you use the STS authorization, you need to fill in. ref:https://help.aliyun.com/document_detail/27364.html*/
      endpoint: '<your endpoint>',
      instancename: '<your instance name>'
    },
    // ...
  },
  // default configuration for all databases
  default: {
 
  },
 
  // load into app, default is open
  app: true,
  // load into agent, default is close
  agent: false,
};

Example

const client1 = app.tabestore.get('db1');
await client1.putRow(params);
//or
yield client1.putRow(params);
 
const client2 = app.tabestore.get('db2');
await client2.putRow(params);
//or
yield client2.putRow(params);

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-tablestore

Weekly Downloads

1

Version

2.0.2

License

MIT

Last publish

Collaborators

  • mumudeveloper