Giter Site home page Giter Site logo

cql-js-driver's Introduction

cql-js-driver

This repo is javascript lib to interact with CovenantSQL local proxy.

Install

Install cql-js-driver via npm or yarn:

npm install --save cql-js-driver

or

yarn add cql-js-driver

Get started

Follow CovenantSQL QuickStart to get you prepared.

use testnet proxy directly

We provides testnet proxy for your testing: http(s)://testnet-proxy.covenantsql.io

const config = {
    endpoint: 'https://testnet-proxy.covenantsql.io',
    dbid: `${DB_ID}`, // your DB id created by `cql` tools in QuickStart
}

if you setup your own proxy

  1. set up CovenantSQL local proxy
$ go get github.com/CovenantSQL/CovenantSQL
$ make bin/cql
$ rsync -avP ./conf/testnet/{config.yaml,private.key} ~/.cql/
$ ./bin/cql -adapter 127.0.0.1:11105
  1. fill in the configs
const config = {
    endpoint: '127.0.0.1:11105', // local testnet endpoint without https
    dbid: `${DB_ID}`, // your DB id created by `cql` tools
}

connect and query

import cql from 'cql-js-driver'

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))

Contribution

  • yarn dev
  • open http://localhost:8080/examples/

License

Apache-2.0.

cql-js-driver's People

Contributors

auxten avatar dependabot[bot] avatar foreseaz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.