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

@cbe/database

v0.0.0-0.1.4.1.0.0

Published

database for (node.)js sdk

Downloads

2

Readme

@cloudbase/database

NPM Version

介绍

提供 TCB JS SDK 操作数据库的接口。

安装

yarn add @cloudbase/database

使用

使用 @cloudbase/database 时,需要提供发送请求的类 reqClass

// index.js

const database = require('@cloudbase/database/').Db;
const Request = require('./request');

class Tcb {
  ...
  database(dbConfig) {
    database.reqClass = Request;
    return new database(dbConfig);
  }
}

实现 Request 类,需要提供异步的 send 方法。

// request.js

// 进一步处理,鉴权等...
const requestHandler = require('requestHandler')

class Request {
  constructor(config) {
    this.config = config
  }

  async send(action, data) {
    const params = Object.assign({}, data, {
      action
    })

    const slowQueryWarning = setTimeout(() => {
      console.warn(
        'Database operation is longer than 3s. Please check query performance and your network environment.'
      )
    }, 3000)

    try {
      return await requestHandler({
        timeout: this.config.timeout,
        config: this.config.config,
        params,
        method: 'post',
        headers: {
          'content-type': 'application/json'
        }
      })
    } finally {
      clearTimeout(slowQueryWarning)
    }
  }
}

module.exports = Request

请求数据样例

{
  "url": "https://tcb-admin.tencentcloudapi.com/admin?eventId=1554896261428_92044",
  "method": "post",
  "timeout": 15000,
  "headers": { "user-agent": "tcb-admin-sdk/1.4.6", "content-type": "application/json" },
  "body": {
    "collectionName": "coll-1",
    "action": "database.addCollection",
    "envName": "base-830cab",
    "timestamp": 1554896261428,
    "eventId": "1554896261428_92044",
    "authorization": "q-sign-algorithm=sha1&q-ak=xxx&q-sign-time=1554896260;1554897160&q-key-time=1554896260;1554897160&q-header-list=content-type;user-agent&q-url-param-list=action;collectionname;envname;eventid;timestamp&q-signature=xxxxx",
    "sdk_version": "1.4.6"
  },
  "json": true
}

开发指南

注意

当前 database 库是通过分支来控制了两个不同的版本,主干版提供给@cloudbase/js-sdk 库使用,feature/support_db_2.0 分支提供给@cloudbase/node-sdk 库使用。

两个分支区别: support_db_2.0 分支进行了数据库接口的升级,将原有的 json 协议转换为 mongo 支持的 bson 协议处理,目的是解决旧接口存在的问题,描述如下

  • 日期对象 是走约定协议处理,即转换为 {$date: timestamp},这种方式应摒弃(EJSON 协议可解决)
  • 无法支持 null, NaN 等特殊类型处理(EJSON 协议可解决)
  • serverDate 这种自定义类型的实现,是继续保留 还是摒弃
  • 接口实现混杂,普通 CRUD 接口均走 flexdb,而聚合,事务又用 runcommand 方式
  • 原插入文档接口返回 docId 形式混杂

目前仅针对服务端 sdk @cloudbase/node-sdk 完成了升级,而客户端 sdk @cloudbase/js-sdk 以及 小程序端 SDK 仍保留为旧接口形式。

开发及发布事项

  1. 数据库接口的改动务必补充测试用例验证
  2. 发布时,约定 feature/support_db_2.0 分支上发布正式版(for @cloudbase/node-sdk)使用,master 分支上发布 beta 版 (for @cloudbase/js-sdk)使用。两 sdk 均通过锁版本方式依赖该库,不会受自动更新依赖影响。