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.