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

dbchain-js-client-sm2

v1.3.20

Published

Javascript client implementation with orm for dbChain cloud service

Downloads

10

Readme

中文

js-client-sm2

for the sm2 crypto version of the js-client sdk


dbChain js-client-sm2 is the JavaScript implementation of the client side library of dbChain, the blockchain database. With the js-client-sm2, developers can quickly start a dbChain application in minutes.

The js-client-sm2 provides JavaScript functions for

  • Generating mnemonic and private/public key pairs
  • Checking whether key exists
  • Accessing passphrase
  • Retrieving list of tables of a database
  • Retrieving the options of a talbe
  • Retrieving columns of a table
  • Retrieving options of a column
  • Inserting a row into a table
  • Retrieving all rows of a table
  • Searching for rows contain certain field value

Install

yarn add dbchain-js-client-sm2

or

npm install --save dbchain-js-client-sm2

Usage

Generating mnemonic and private/public key pais

import { newMnemonic, createAndStoreKey } from "dbchain-js-client-sm2";

const mnemonic = newMnemonic();
// brown deliver ignore estate adjust pond final inject wear return sword silent
const passphrase = "123345678"
createAndStoreKey(mnemonic, passphrase)

Checking whether key exists

import { hasKey } from 'dbchain-js-client-sm2;
if(!hasKey()) {
  console.log("User needs to generate and save key pairs")
}

Accessing passphrase

import { hasPassphrase, savePassphrase } from 'dbchain-js-client-sm2;

if(!hasPassphrase()) {
  console.log("User needs to input passphrase");
}

// when user login with a passphrase, we usually save it to browser session storage
var passphrase = "12345678"
if (savePassphrase(passphrase)) {
  console.log("passphrase saved successfully");
} else {
  console.log("passphrase is invalid");
}

Retrieving list of tables of a database

import { getTables } from "dbchain-js-client-sm2";

const appCode = "DJ1PGEQ45A";
const tables = await getTables(appCode);
/*
[
  "supplier",
  "product",
  "customer"
]
*/

Retrieving the options of a table

import { getTableOptions } from "dbchain-js-client-sm2";

const appCode = "DJ1PGEQ45A";
const tableName = "supplier";
const options = await getTableOptions(appCode, tableName);
/*
[
  "public"
]
*/

Retrieving columns of a table

import { getTable } from "dbchain-js-client-sm2";

const appCode = "DJ1PGEQ45A";
const tableName = "supplier";
const options = await getTable(appCode, tableName);
/*
[
  "name",
  "phone",
  "address_id"
]
*/

Retrieving options of a column

import { getFieldOptions } from "dbchain-js-client-sm2";

const appCode = "DJ1PGEQ45A";
const tableName = "supplier";
const fieldName = "phone";
const options = await getFieldOptions(appCode, tableName, fieldName);
/*
[
  "not-null"
]
*/

Inserting a row into a table

import { insertRow } from "dbchain-js-client-sm2";

const appCode = "DJ1PGEQ45A";
const tableName = "supplier";

var record = {};
record.name = "Super supplier"
record.phone = "18888888888";
record.address_id = "5";

const options = await insertRow(appCode, tableName, record, function() {
  console.log("inserting record succeeded");
});

Retrieving id of all rows in a table

import { getAllIds } from "dbchain-js-client-sm2";

const appCode = "DJ1PGEQ45A";
const tableName = "supplier";
const ids = await getAllIds(appCode, tableName);
/*
[
  "1",
  "2",
  "3",
  "4"
]
*/

Retrieving a row from a table

import { getRow } from "dbchain-js-client-sm2";

const appCode = "DJ1PGEQ45A";
const tableName = "supplier";
const record = await getRow(appCode, tableName, "1");
/*
{
  name: "Super supplier",
  phone: "18888888888",
  address_id: "5"
}
*/

License

dbChain js-client-sm2 is licensed under the Apache-2.0 License.