rqlite-connect

nodejs client for rqlite, with cluster support

Usage no npm install needed!

<script type="module">
  import rqliteConnect from 'https://cdn.skypack.dev/rqlite-connect';
</script>

README

rqlite-client

NPM Version Build Status Node.js Version

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