2.0.0 • Published 7 years ago
rqlite-connect v2.0.0
rqlite-client
nodejs client for rqlite, with cluster support, documentation
const { Client } = require('rqlite-client')
const client = new Client(['http://localhost:4001', 'http://localhost:4003'])
const schema = `\
CREATE TABLE IF NOT EXISTS account (
  id integer not null primary key,
  name text,
  balance integer not null default 0
)`
async function main() {
    await client.exec(schema)
    await client.exec('INSERT INTO account(name, balance) VALUES("foo", 10)')
    await client.exec('INSERT INTO account(name, balance) VALUES("bar", 10)')
    await client.batch([
        'UPDATE ACCOUNT SET balance = balance - 1 WHERE name = "foo"',
        'UPDATE ACCOUNT SET balance = balance + 1 WHERE name = "bar"',
    ], true) // true for atomic
    await client.query('SELECT * FROM account')
}2.0.0
7 years ago