pg-template-tag
Build a { text, values } object for use with brianc/node-postgres. Supports nesting.
Example
Write the query as-is inside template literals, use ${}
interpolation to
supply values.
var SQL = ;connection;connection;
Pieces are reusable, so you can:
var fields = SQL`name, time, score, history_avg(score) as "scoreAvg"`;connection;connection;
Values are reused within the query if the piece is reused.
var ids = SQL``;var query = SQL` select name from a where id = any() union all select name from b where id = any()`;querytext; // 'select ... where id = any($1) union all select ... where id = any($1)'queryvalues; // [[1, 2, 3]]
There's a .join
function analog to Array.prototype.join
to join together literals.
{ var conditions = ; if filteremail conditions; if filterminAge conditions; if filtermaxAge conditions; return connection;}