Registry / database / sql-bricks-postgres

sql-bricks-postgres

JSON →
library0.6.0jsnpmunverified

A lightweight, schemaless SQL generation library for PostgreSQL, built on top of sql-bricks. It adds PostgreSQL-specific features such as LIMIT/OFFSET, RETURNING, UPDATE...FROM, DELETE...USING, ON CONFLICT (UPSERT), and FROM VALUES. Version 0.6.0 is stable but sees infrequent releases. Key differentiator: provides a fluent API for generating parameterized SQL with PostgreSQL syntax, using $1, $2 placeholders for safe execution via database libraries. Designed for use with pg-bricks for query execution, but can be used standalone.

database
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CommonJS require returns the sql-bricks object directly, no default property.

const sql = require('sql-bricks-postgres');

ESM default import is the preferred modern approach.

import sql from 'sql-bricks-postgres';

Demonstrates select, insert with RETURNING, and upsert (ON CONFLICT DO UPDATE) using parameterized queries.

const sql = require('sql-bricks-postgres'); // Select with parameterized query const query = sql.select().from('user').where({name: 'Fred'}).toParams(); console.log(query); // { text: 'SELECT * FROM "user" WHERE name = $1', values: ['Fred'] } // Insert with return const insertQuery = sql.insert('user', {name: 'Alice', age: 30}).returning('id').toParams(); console.log(insertQuery); // { text: 'INSERT INTO "user" (name, age) VALUES ($1, $2) RETURNING id', values: ['Alice', 30] } // Upsert const upsertQuery = sql.insert('user', {name: 'Bob', age: 25}) .onConflict('name').doUpdate(['age']).toParams(); console.log(upsertQuery); // { text: 'INSERT INTO "user" (name, age) VALUES ($1, $2) ON CONFLICT (name) DO UPDATE SET age = EXCLUDED.age', values: ['Bob', 25] }
Debug
Known footguns
gotchaNever use .toString() to build SQL for execution; use .toParams() to get parameterized query safe from SQL injection.
deprecatedThe .onConflict().doUpdate() with no argument updates all columns automatically. This behavior may change; specify columns explicitly.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
7 hits · last 30 days
gptbot
3
ahrefsbot
1
Resources