postgres-fp

1.4.1 • Public • Published

postgres-fp

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

A wrapper around postgres in a functional programming style

Installation

npm install --save postgres-fp

Example

With righto

const righto = require('righto')
const connect = require('postgres-fp/connect')
const execute = require('postgres-fp/execute')
const getAll = require('postgres-fp/getAll')
 
const connection = righto(connect, {
  hostname: 'localhost',
  port: 1000
})
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)
})

With promises

const postgres = require('postgres-fp/promises');
 
async function getTestRecords () {
  const connection = await postgres.connect({
    hostname: 'localhost',
    port: 1000
  });
 
  await postgres.execute(connection, 'CREATE TABLE lorem (info TEXT)');
 
  const results = await postgres.getAll(connection, 'SELECT * FROM test');
 
  console.log(results);
}

Functions signatures

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

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

insert -> connection -> tableName -> object -> (error, result={lastId, changes})

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

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

batch (not implemented yet)

close -> connection -> (error)

License

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

Package Sidebar

Install

npm i postgres-fp

Weekly Downloads

3

Version

1.4.1

License

ISC

Unpacked Size

16.7 kB

Total Files

14

Last publish

Collaborators

  • markwylde