egg-tablestore

[egg-tablestore]

用了阿里的eggjs,感觉很舒服,刚好最近想试试tablestore,看到没有egg版的tablestore库,然后决定自己动手写一个,希望大家提提意见。

egg-tablestore
egg-tablestore
egg-tablestore
egg-tablestore
egg-tablestore
egg-tablestore

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

上一篇:基于阿里的Node全栈之路(一)部署Docker


下一篇:PHP 源码探秘 - 因为 Java 和 Php 在获取客户端 cookie 方式不同引发的 bug