
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@rivethealth/pg-template-tag
Advanced tools
ECMAScript 6 (2015) template tag function to write queries for node-postgres.
Build a { text, values } object for use with brianc/node-postgres. Supports nesting.
Write the query as-is inside template literals, use ${} interpolation to
supply values.
var SQL = require("pg-template-tag");
connection.query(SQL`select name from user where id=${id}`);
connection.query(SQL`select value from record where ${ lower===null ? SQL`true` : SQL`time > ${lower}`}`);
Pieces are reusable, so you can:
var fields = SQL`name, time, score, history_avg(score) as "scoreAvg"`;
connection.query(SQL`select ${fields} from scores where time > current_date`);
connection.query(SQL`select ${fields} from scores where score > ${minScore}`);
Values are reused within the query if the piece is reused.
var ids = SQL`${[1, 2, 3]}`;
var query = SQL`
select name from a where id = any(${ids})
union all
select name from b where id = any(${ids})
`;
query.text; // 'select ... where id = any($1) union all select ... where id = any($1)'
query.values; // [[1, 2, 3]]
There's a .join function analog to Array.prototype.join to join together literals.
function filterUsers(filter) {
var conditions = [];
if (filter.email) conditions.push(SQL`email like ${filter.email}`);
if (filter.minAge) conditions.push(SQL`age > ${filter.minAge}`);
if (filter.maxAge) conditions.push(SQL`age < ${filter.maxAge}`);
return connection.query(SQL`select * from users where ${SQL.join(conditions, ' and ')}`);
}
FAQs
ECMAScript 6 (2015) template tag function to write queries for node-postgres.
We found that @rivethealth/pg-template-tag demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.