Skip to content

Instantly share code, notes, and snippets.

@jakub-roman jakub-roman/build_query.js
Last active Jan 10, 2019

Embed
What would you like to do?
const format = require('pg-format')
var filter = [
{
c: "id",
o: "=",
v: "1"
},
{
c: "name",
o: "like",
v: "doasidn"
}
]
var insertFinJobs = function( filter ) {
var f = filter.map( i => { return `${i.c} ${i.o} '${i.v}'` } ).join(" AND ")
return format('select * from jobs_finished where 1 = 1 %s', f ? `AND ${f}` : '' )
}
console.log( insertFinJobs(filter) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.