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

simple-aliyun-tablestore

v1.2.3

Published

SAT, 简化的阿里云表格存储TableStore Nodejs SDK,适合小型项目快速构建。

Downloads

10

Readme

simple-aliyun-tablestore (SAT)

阿里云表格存储功能强大,因而API非常繁琐,在只需要完成简单的数据存储功能时非常麻烦。此项目对阿里云的表格存储Nodejs SDK进行简化封装,用一部分功能的代价换取简单方便的接口,方便敏捷开发。此项目省略的功能包括:

  1. 版本:不考虑多版本表格,也不考虑数据写入的时间戳。
  2. 表操作:不支持对表的操作,仅支持对数据的读写。
  3. 整数:整数数字会被自动转化为整数类型。
  4. 主键:默认使用一个主键id,但是支持自定义主键和多主键,请参考主键
  5. 多元索引:仅支持少数多元索引功能

接口文档

开始使用

npm i simple-aliyun-tablestore

为了支持函数计算等应用场景,在已经安装官方Nodejs SDK tablestore的前提下,您可以直接复制文件/SAT.js,并通过require('./SAT.js')的方式引入。

const SAT = require('simple-aliyun-tablestore')

SAT.init('endpoint', 'instance', 'akId', 'akSecret')

async function test () {
  const table = SAT('tablename')
  await table.put('rowid', { hello: 'world!' })
  const res = await table.get('rowid')
  console.log(res)
}
test()

更多例子

约定

常量

新增了短的常量符号,与官方常量的对照关系如下:(官方的常量依然支持)

I   IGNORE
E   EXPECT_EXIST
NE  EXPECT_NOT_EXIST

==  EQUAL
!=  NOT_EQUAL
>   GREATER_THAN
>=  GREATER_EQUAL
<   LESS_THAN
<=  LESS_EQUAL

!   NOT
&&  AND
||  OR

条件

条件变量c可以描述行的存在条件,也可以同时描述列条件。常规情况下,c是一个如下格式的数组:

c = ['E', ['num', '==', 10], ['space', '>', 10]]

数组首个元素是字符串,指定期望的行条件。从第二个元素开始,每个元素是一个长度为3的数组,描述一个列条件。多个列条件默认使用逻辑与连接。

上述例子中的条件表示:期望行存在 and num属性值等于10 and space属性值大于10

当不需要列条件时,条件变量c可以省略为一个字符串,描述期望的行条件。

主键

若需要多个主键或自定义主键,需要在生成表的操作对象时指定,并在传入主键时按顺序传入数组,例如:

const opt = SAT('tablename', ['pk1', 'pk2'])
const res = await opt.get(['pk1value', 123])

接口

const SAT = require('simple-aliyun-tablestore')

辅助接口

// 初始化
SAT.init('endpoint', 'instancename', 'accessKeyId', 'accessKeySecret', 'securityToken')

// 访问原始client对象,若传入c,则使用c替换client
SAT.client(c)

// utils
SAT.utils = { parseInt(v), condition(c), pk(k, pks), params(k, c, t, pks), wrap(k, row, pks), wrapRows(rows, pks, res), columns(attrs), attrColumns(attrs) }

基础接口

调用SAT('tablename')生成操作对象。

例子

// 查询单行数据
SAT('tablename').get('id', cols = [])

// 覆盖单行数据
SAT('tablename').put('id', { keys: 'values' }, c = 'I')

// 删除单行数据
SAT('tablename').del('id', c = 'I')

高级接口

// 扫描连续的主键
// 返回对象,键为行对应的主键逗号连接,值为行数据对象
SAT('tablename').getRange('startid', 'endid', cols = [])

// 批量读取,自动分片
// 返回对象,键为行对应的主键逗号连接,值为行数据对象
SAT('tablename').getBatch(['id1', 'id2', 'id3'], cols = [])

// 更新
// u为更新内容:
// 若u不为对象,则理解为更新属性值
// 若u为对象且u.del为真,则删除此属性
// 若u为对象且u.inc存在,则自增此属性,步长为u.inc
SAT('tablename').update('id', { 'keyToUpdate': u }, c = 'I')

// 批量写入,自动分片
// 接受数组,每个项目为一个数组描述一个写入操作
// 写入操作的第一个项目为写入类型,支持put(PUT), update(UPDATE), del(DELETE)
// 第二个项目开始,与update, put, del的参数一致
SAT('tablename').writeBatch([
  ['put', 'id1', { hello: 'hi' }, 'I'],
  ['update', 'id2', { hello: { del: 1 } }],
  ['del', 'id3']
])

// 多元索引
// 目前仅支持精确匹配
SAT('tablename').search('index', ['fieldName', 'value'])