2.0.10 • Published 1 year ago

open-test-db v2.0.10

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Use JavaScript to access OpenDB

Front-end developers could use opendb-proxy-js to access OpenDB through OpenDB Adapter.

Installation

This package requires Node.js version 18.0.0 or above.

Install node-opendb using package manager npm or yarn:

npm install --save node-opendb

or

yarn add node-opendb

Quick start

First, Deploy Adapter Service.

Configure node-opendb, replace adapter_listen_address with adapter listen address, replace database_id with created database id:

const config = {
    endpoint: '<adapter_listen_address>', // local testnet endpoint without https
    database: 'database_id', // your DB id created by `cql` tools
}

After successfully connected to adapter, any CRUD operation is available using typical database operations:

const cql from 'node-opendb'

const config = {...} // see above

cql.createConnection(config).then(async (connection: any) => {
    // read
    const data1 = await connection.query("select ? + ?", [2.1, 3.2]);
    console.log(data1);

    // write
    const createTableSQL = `
    CREATE TABLE IF NOT EXISTS contacts (\
    contact_id INTEGER PRIMARY KEY,
    first_name TEXT NOT NULL,
    last_name TEXT NOT NULL,
    email text NOT NULL UNIQUE,
    phone text NOT NULL UNIQUE
    );
    `
    const status1 = await connection.exec(createTableSQL)
    console.log(`exec1 status:`, status1);

    const data2 = await connection.query("show tables;");
    console.log(data2);
}).catch((e: any) => console.log(e))
2.0.9

1 year ago

2.0.10

1 year ago

2.0.8

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago