postgres-fp
v1.4.1
Published
A wrapper around postgres in function programming style
Downloads
4
Maintainers
Readme
postgres-fp
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.