chaingres
Postgres: Unchained. Use cascading style programming to structure your Postgres queries.
By Chris Cates :star:
Installation
npm install chaingres --save
Usage
Here is a sample demo to use chaingres:
var chaingres = require("./chaingres");
var postgres = require("pg");
var queryConn = "postgres://"+name+":"+password+"@"+host+":"+port+"/"+db+"";
client = new pg.Client(queryConn);
//Example INSERT
chaingres
.new(client)
.insert({
"column1": "value1",
"column2": "value2"
}).then(function(err,result) {
console.log(result);
})
//Example SELECT
chaingres
.new(client)
.select(["c1", "c2"])
.from("table")
.join({
"table": "table2",
"on": [{
"column": "tableId",
"op": "=",
"fromTable": "table",
"fromColumn": "id"
}]
})
.order({
"table": "table2",
"column": "id",
"order": "ASC"
})
.limit(10)
.offset(0)
.then(function(err,result) {
//This will return a bunch of rows
console.log(result);
})