1.4.1 • Published 4 years ago

postgres-fp v1.4.1

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

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.

1.4.1

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago