rqlite-fp

2.10.1 • Public • Published

rqlite-fp

Build Status David DM GitHub code size in bytes GitHub package.json version GitHub

A client library for rqlite in a functional programming style

Installation

npm install --save rqlite-fp

Example

With promises

const rqlite = require('rqlite-fp/promises');
 
(async function () {
  const connection = await connect('http://localhost:4001')
  const tableCreated = await execute(connection, 'CREATE TABLE lorem (info TEXT)')
  const testResults = await getAll(connection, 'SELECT * FROM test')
 
  console.log(results)
}())

With callbacks

const connect = require('rqlite-fp/connect')
const execute = require('rqlite-fp/execute')
const getAll = require('rqlite-fp/getAll')
 
function getTestRecords (callback) {
  connect('http://localhost:4001', function (error, connection) {
    if (error) { return callback(error) }
    execute(connection, 'CREATE TABLE lorem (info TEXT)', function (error, tableCreated) {
      if (error) { return callback(error) }
      getAll(connection, 'SELECT * FROM test', function (error, testResults) {
        if (error) { return callback(error) }
        callback(null, testResults)
      })
    })
  })
}
 
getTestRecords(function (error, testRecords) {
  if (error) {
    throw error
  }
  console.log(testRecords)
})

With righto

const righto = require('righto')
const connect = require('rqlite-fp/connect')
const execute = require('rqlite-fp/execute')
const getAll = require('rqlite-fp/getAll')
 
const connection = righto(connect, 'http://localhost:4001')
const tableCreated = righto(execute, connection, 'CREATE TABLE lorem (info TEXT)')
const testResults = righto(getAll, connection, 'SELECT * FROM test', righto.after(tableCreated))
 
testResults(function (error, results) {
  if (error) {
    throw error
  }
 
  console.log(results)
})

Functions signatures

start -> {httpAddr, raftAddr, join} -> (error, connection)

connect -> filename -> [mode] -> (error, connection)

run -> connection -> sql -> [parameters] -> (error, result={lastId, changes})

getAll -> connection -> sql -> (error, rows)

getOne -> connection -> sql -> (error, row)

batch -> connection -> sql -> [[parameters]] -> (error, result={lastId, changes})

execute -> connection -> sql -> (error, connection)

close -> connection -> (error)

License

This project is licensed under the terms of the MIT license.

Package Sidebar

Install

npm i rqlite-fp

Weekly Downloads

1

Version

2.10.1

License

ISC

Unpacked Size

25.9 kB

Total Files

17

Last publish

Collaborators

  • markwylde