egg-tablestore

  1. 云栖社区>
  2. 博客>
  3. 正文

egg-tablestore

木木工程师 2017-09-23 11:48:14 浏览878
展开阅读全文

[egg-tablestore]

用了阿里的eggjs,感觉很舒服,刚好最近想试试tablestore,看到没有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

网友评论

登录后评论
0/500
评论
木木工程师
+ 关注