Proxy version is build for both web and node environment, so now moved to covenantsql-proxy-js.
This repo is nodejs driver for CovenantSQL written by TypeScript.
Install node-covenantsql via npm or yarn:
npm install --save node-covenantsqlor
yarn add node-covenantsqlFollow CovenantSQL Quickstart to get you prepared.
- If the CovenantSQL endpoint comes with
HTTPSthen.pemand.keyfiles are needed for requests:
constconfig={endpoint: 'e.morenodes.com:11108',// testnet endpoint with httpsdatabase: `${DB_ID}`,// your DB id created by `cql` toolskey_dir: path.resolve(`${KEY_FILE_RELATIVE_PATH}`),// your key filehttps_pem_dir: path.resolve(`${PEM_FILE_RELATIVE_PATH}`)// your pem file (cert file)}- If only
HTTPis needed, then your config could be:
constconfig={endpoint: 'localhost:11105',// local testnet endpoint without httpsdatabase: `${DB_ID}`,// your DB id created by `cql` toolsbypassPem: true// bypass https config}importcqlfrom'node-covenantsql'constconfig={...}// see abovecql.createConnection(config).then(async(connection: any)=>{// readconstdata1=awaitconnection.query("select ? + ?",[2.1,3.2]);console.log(data1);// writeconstcreateTableSQL=` 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 ); `conststatus1=awaitconnection.exec(createTableSQL)console.log(`exec1 status:`,status1);constdata2=awaitconnection.query("show tables;");console.log(data2);}).catch((e: any)=>console.log(e))