
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
pgsmith is a utility for safely building parameterized SQL queries for use with Postgres and pg.
This is not an ORM or DSL. It’s a simple, composable SQL builder that lets you write SQL the way you want — clearly and safely.
const emails = ['alice@example.com', 'bob@example.com'];
const query = sql`
SELECT *
FROM users
WHERE email IN (${emails}) AND is_active = ${true}
`;
// query.text:
// SELECT * FROM users WHERE email IN ($1, $2) AND is_active <= $3
// query.values:
// ['alice@example.com', 'bob@example.com', true]
🔐 Safe & Convenient
$1, $2, …) to prevent SQL injection.IN ($1, $2, ...).{text, values} — drop-in compatible with pg.query().🧰 Flexible Builder API
🛠️ Object Helpers
INSERT, UPDATE, WHERE, UNNEST, and other SQL Fragments from objects.📦 Tested & Stable
npm i pgsmith
import {sql} from 'pgsmith';
const ids = [33, 22, 11];
const query = sql`
SELECT * FROM logs
WHERE id IN (${ids})
AND level <= ${5}
ORDER BY created_at DESC
`;
// pg.query(query)
// query.text:
// SELECT * FROM logs WHERE id IN ($1, $2, $3) AND level <= $4 ORDER BY created_at DESC
// query.values:
// [33, 22, 11, 5]
import {sql, sqlBuilder, raw} from 'pgsmith';
// example data, could be anything
const data = {
id: 42,
status: 'active',
role: ['admin', 'editor'],
order: 'created_at DESC',
}
const builder = sqlBuilder(sql`SELECT * FROM users WHERE 1=1`);
data.id && builder.add(sql`AND id = ${data.id}`);
data.status && builder.add(sql`AND status = ${data.status}`);
data.role && builder.add(sql`AND role IN (${data.role})`);
data.order && builder.add(sql`ORDER BY ${raw('data.order')}`);
const query = builder.build();
// query.text:
// SELECT * FROM users WHERE 1=1 AND id = $1 AND status = $2 AND role IN ($3, $4) ORDER BY created_at DESC
// query.values:
// [42, 'active', 'admin', 'editor']
See a more real-world example of dynamic query building here.
import { buildInsert } from 'pgsmith';
const user = {
firstName: 'Alice',
lastName: 'Smith',
email: 'alice@example.com',
isActive: true,
};
const query = buildInsert('users', user, { returning: true });
// query.text:
// INSERT INTO "users" ("firstName", "lastName", "email", "isActive")
// VALUES ($1, $2, $3, $4) RETURNING *
// query.values:
// ['Alice', 'Smith', 'alice@example.com', true]
If you're inserting many rows, or want to take advantage of prepared statements, use UNNEST via buildUnnest.
UNNEST can offer massive performance improvements for large inserts, as it allows PostgreSQL to optimize the query execution plan.
import { sql, sqlBuilder, buildWhere } from 'pgsmith';
const query = sqlBuilder(sql`SELECT * FROM users`)
.add(buildWhere({id: 1, status: 'active', role: ['admin', 'editor']}))
.add(sql`ORDER BY created_at ${raw('DESC')}`)
.build();
// query.text:
// SELECT * FROM users WHERE "id" = $1 AND "status" = $2 AND "role" IN ($3, $4) ORDER BY created_at DESC
// query.values:
// [1, 'active', 'admin', 'editor']
There are more examples in the API Reference.
pgpgsmith works seamlessly with pg, the most popular PostgreSQL client for Node.js.
Just pass the { text, values } object directly to pg.query():
import { sql } from 'pgsmith';
import { Client } from 'pg';
const client = new Client();
await client.connect();
const query = sql`SELECT * FROM users WHERE id = ${42}`;
const result = await client.query(query);
await client.end();
console.log(result.rows);
// → [{ id: 42, name: 'Alice', ... }]
See the API Reference for detailed documentation on all functions and types.
Most SQL libraries either go too far or not far enough.
$1 bindings.pgsmith doesn’t try to replace SQL. It gives you a tiny, composable toolset that lets you work with SQL — clearly, safely, and without repetition or risk.
Write SQL the way you want — clearly and safely.
main — all tests must pass.FAQs
A tiny utility for building safe, parameterized SQL queries with `pg`.
The npm package pgsmith receives a total of 21 weekly downloads. As such, pgsmith popularity was classified as not popular.
We found that pgsmith demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.