Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/covenantsql/cql-js-driver
Interact with CovenantSQL via proxy in web and node
https://github.com/covenantsql/cql-js-driver
covenantsql cql npm-package
Last synced: about 1 month ago
JSON representation
Interact with CovenantSQL via proxy in web and node
- Host: GitHub
- URL: https://github.com/covenantsql/cql-js-driver
- Owner: CovenantSQL
- License: apache-2.0
- Created: 2019-03-12T06:58:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-03T01:45:24.000Z (about 2 years ago)
- Last Synced: 2023-08-13T05:10:41.576Z (over 1 year ago)
- Topics: covenantsql, cql, npm-package
- Language: TypeScript
- Homepage:
- Size: 269 KB
- Stars: 5
- Watchers: 3
- Forks: 5
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cql-js-driver
This repo is javascript lib to interact with [CovenantSQL](https://github.com/CovenantSQL/CovenantSQL) local proxy.
## Install
Install `cql-js-driver` via npm or yarn:
```bash
npm install --save cql-js-driver
```
or
```bash
yarn add cql-js-driver
```## Get started
Follow CovenantSQL [QuickStart](https://testnet.covenantsql.io/quickstart) to get you prepared.### use testnet proxy directly
We provides testnet proxy for your testing: `http(s)://testnet-proxy.covenantsql.io`
```javascript
const config = {
endpoint: 'http://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
```bash
$ 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
```2. fill in the configs
```javascript
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
```typescript
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](LICENSE).