{"id":20859637,"url":"https://github.com/inlym/egg-aliyun-tablestore","last_synced_at":"2025-05-12T08:32:39.755Z","repository":{"id":57220267,"uuid":"309312066","full_name":"inlym/egg-aliyun-tablestore","owner":"inlym","description":"🚚 阿里云表格存储（Tablestore）插件，用于 Egg.js 框架","archived":false,"fork":false,"pushed_at":"2020-11-13T04:40:04.000Z","size":12,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-07T08:17:09.385Z","etag":null,"topics":["aliyun","awesome","database","egg","egg-plugin","eggjs","eggplugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inlym.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-02T08:58:53.000Z","updated_at":"2024-07-02T04:26:56.000Z","dependencies_parsed_at":"2022-08-29T00:11:58.456Z","dependency_job_id":null,"html_url":"https://github.com/inlym/egg-aliyun-tablestore","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fegg-aliyun-tablestore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fegg-aliyun-tablestore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fegg-aliyun-tablestore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fegg-aliyun-tablestore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inlym","download_url":"https://codeload.github.com/inlym/egg-aliyun-tablestore/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225130723,"owners_count":17425506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aliyun","awesome","database","egg","egg-plugin","eggjs","eggplugin"],"created_at":"2024-11-18T04:50:51.318Z","updated_at":"2024-11-18T04:50:51.797Z","avatar_url":"https://github.com/inlym.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# egg-aliyun-tablestore\n\n[![npm version](https://img.shields.io/npm/v/egg-aliyun-tablestore)](https://www.npmjs.com/package/egg-aliyun-tablestore)  [![MIT](https://img.shields.io/npm/l/egg-aliyun-tablestore)](https://github.com/inlym/egg-aliyun-tablestore/blob/master/LICENSE)  [![npm](https://img.shields.io/npm/dw/egg-aliyun-tablestore)](https://www.npmjs.com/package/egg-aliyun-tablestore)\n\n\n![egg-aliyun-tablestore](https://img.inlym.com/13766eda453d41ab90154a41a2eb7847.jpg)\n\n\n\n阿里云表格存储（Tablestore）插件，用于 Egg.js 框架。\n\n\n\n## 目录\n\n-   [介绍](#介绍)\n-   [安装](#安装)\n-   [使用](#使用)\n    -   [启用插件](#启用插件)\n    -   [配置方式](#配置方式)\n    -   [使用说明](#使用说明)\n-   [相关](#相关)\n-   [作者](#作者)\n-   [参与](#参与)\n-   [许可证](#许可证)\n\n\n\n## 介绍\n\n本插件的工作只是将表格存储（Tablestore）官方 Node.js SDK 挂载到 Egg.js 框架上，使其能够被便捷地使用。对于表格存储的内部方法，请查看 [官方文档](https://help.aliyun.com/document_detail/56350.html?userCode=lzfqdh6g) 。\n\n\n\n## 安装\n\n按照通用的方式使用 npm 下载安装到你的项目下即可，无需全局安装。\n\n\n\n安装命令：\n\n```bash\n$ npm i egg-aliyun-tablestore\n```\n\n\n\n## 使用\n\n在使用前，请确保你已经阅读 Egg.js 框架关于**插件**的 [文档](https://eggjs.org/zh-cn/basics/plugin.html) 。\n\n\n\n下面说明如何配置以及使用插件。\n\n\n\n### 启用插件\n\n在 `config/plugin.js` 文件中中声明启用 `egg-aliyun-tablestore` 插件：\n\n```js\nexports.tablestore = {\n  /** 是否启用插件，true 为启用，false 为禁用 */\n  enable: true,\n\n  /** 指定插件使用的包，为 'egg-aliyun-tablestore' */\n  package: 'egg-aliyun-tablestore',\n}\n```\n\n在 `config/config.${env}.js` 配置各个环境的实例信息。\n\n\n\n### 配置方式\n\n根据实例数量分为 **单实例配置** 和 **多实例配置** 两种配置方式，使用上也略有不同。\n\n\n\n#### 单实例配置\n\n```js\nexports.tablestore = {\n  // 单实例配置，注意对象属性名为 client，请将 xxxxxxxxxxxx 替换成实际的内容\n  client: {\n    /** AccessKey ID，必填 */\n    accessKeyId: 'xxxxxxxxxxxx',\n\n    /** AccessKey Secret，必填 */\n    accessKeySecret: 'xxxxxxxxxxxx',\n\n    /** endpoint 地址，必填 */\n    endpoint: 'xxxxxxxxxxxx',\n\n    /** 实例名称，必填 */\n    instancename: 'xxxxxxxxxxxx',\n\n    /** 最大重试次数，默认20次，选填 */\n    maxRetries: 20,\n  },\n\n  /** 是否挂载到 app 上，默认开启，选填 */\n  app: true,\n\n  /** 是否挂载到 agent 上，默认关闭，选填 */\n  agent: false,\n}\n```\n\n\n\n如果你不清楚上述配置项是什么含义或者不知道应该填什么，请 [查看官方文档](https://help.aliyun.com/document_detail/56352.html?userCode=lzfqdh6g) 。\n\n\n\n### 多实例配置\n\n```js\nexports.tablestore = {\n  // 多实例配置，注意对象属性名为 clients，底下包含多个对象，一个对象为一个实例，对象的属性名用于后面获取实例\n  clients: {\n\t/** 下面的 ots1 为自定义的实例名，用于后续获取实例，你可以自定义为任意名称 */\n    ots1: {\n      // 实例内部属性与单实例模式相同\n      accessKeyId: 'xxxxxxxxxxxx',\n      accessKeySecret: 'xxxxxxxxxxxx',\n      endpoint: 'xxxxxxxxxxxx',\n      instancename: 'xxxxxxxxxxxx',\n      maxRetries: 20,\n    },\n\n    ots2: {\n      accessKeyId: 'xxxxxxxxxxxx',\n      accessKeySecret: 'xxxxxxxxxxxx',\n      endpoint: 'xxxxxxxxxxxx',\n      instancename: 'xxxxxxxxxxxx',\n      maxRetries: 20,\n    },\n    // ... 其他实例\n\n  },\n\n  /** 所有实例配置的默认值 */\n  default: {\n    // 多个实例中共同的属性可以抽出来放在这里，一般没必要\n  },\n\n  /** 是否挂载到 app 上，默认开启，选填 */\n  app: true,\n\n  /** 是否挂载到 agent 上，默认关闭，选填 */\n  agent: false,\n}\n```\n\n\n\n### 使用说明\n\n单实例模式和多实例模式在使用上存在差异，请查看以下使用方式。\n\n\n\n#### 单实例使用方式\n\n单实例下，可以直接访问 `app` 的 `tablestore` 属性或者 `ots` 属性访问实例。（ `ots` 是 `tablestore` 的别名，两者完全一致，建议使用 `ots` ，因为更简短。）\n\n```js\n// callback 方式调用\napp.tablestore.listTable({}, function (err, data) {\n  if (err) {\n    console.log('error:', err)\n    return\n  }\n  console.log('success:', data)\n})\n\n// 或者使用 ots 属性访问（下同）\napp.ots.listTable({}, function (err, data) {\n  if (err) {\n    console.log('error:', err)\n    return\n  }\n  console.log('success:', data)\n})\n\n// promise 方式调用\nasync ()=\u003e{\n  const data = await app.ots.listTable({})\n  console.log(data)\n}\n```\n\n\n\n#### 多实例使用方式\n\n多实例使用方式和单实例类似，只是 **获取实例的方式** 变了，原来可以直接访问 `app.ots` 获取实例，变更为 `app.ots.get(otsName)` 获取。\n\n```js\nconst client1 = app.ots.get('ots1')\n```\n\n\n\n#### 获取原始类\n\n静态属性、方法调用时，需要获取原始的 `TableStore` 类，可以使用访问 `app.TableStore` 来获取。\n\n\n\n## 相关\n\n以下是作者开发的 Egg.js 框架的插件系列，已用于作者的生产项目中，推荐使用。\n-   [egg-apigw-tracer](https://github.com/inlym/egg-apigw-tracer) - ⚡ 适配 API 网关的 HTTP 请求示踪器，用于 Egg.js 框架\n-   [egg-aliyun-tablestore](https://github.com/inlym/egg-aliyun-tablestore) - 🚚 阿里云表格存储（Tablestore）插件，用于 Egg.js 框架\n-   [egg-load](https://github.com/inlym/egg-load) - 🚀 自动挂载第三方模块至 Egg.js 框架上\n\n\n\n## 作者\n\n我是 [inlym](https://www.inlym.com) ，一个产品经理和全栈开发者。\n\n\n\n如果你有任何问题或者建议，欢迎联系我，以下是我的联系方式：\n\n-   邮箱：inlym@qq.com\n-   主页：[www.inlym.com](https://www.inlym.com)\n\n\n\n## 参与\n\n非常欢迎你能够参与这个项目的开发和维护。\n\n你可以通过以下几种方式参与到项目中：\n\n1.  提建议和需求。对于几句话就能说清楚的建议和需求，你可以直接 提一个 [New Issue](https://github.com/inlym/egg-aliyun-tablestore/issues/new) 。\n2.  Fork 项目，修改代码，然后提交 Pull requests 。（提交前请检查务必通过 ESLint 检查）\n\n\n\n## 许可证\n\n本插件使用 [MIT](LICENSE) 许可证。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlym%2Fegg-aliyun-tablestore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finlym%2Fegg-aliyun-tablestore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlym%2Fegg-aliyun-tablestore/lists"}