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.

npm install sql-bricks-postgres
INSTALL
IMPORT
SIG · SQL-BRICKS-POSTGRE
S
sql-bricks-postgres
databasejavascriptv0.6.0
harness data pending
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.

default import (CommonJS)
const sql = require('sql-bricks-postgres');
const sql = require('sql-bricks-postgres').default;
CommonJS require returns the sql-bricks object directly, no default property.
default import (ESM)
import sql from 'sql-bricks-postgres';
import * as sql from 'sql-bricks-postgres';
ESM default import is the preferred modern approach.

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 issues
gotchaNever use .toString() to build SQL for execution; use .toParams() to get parameterized query safe from SQL injection.
fix
Always call .toParams() and pass the {text, values} to your database driver.
affects: >=0.1.0
deprecatedThe .onConflict().doUpdate() with no argument updates all columns automatically. This behavior may change; specify columns explicitly.
fix
Provide an array of columns to .doUpdate(columns) to avoid implicit behavior.
affects: <0.7.0
Errors
Common errors & fixes
TypeError: sql_bricks_postgres is not a function
Using import { sql } from 'sql-bricks-postgres' incorrectly; the default export is a function.
fix
Use: const sql = require('sql-bricks-postgres'); or import sql from 'sql-bricks-postgres';
Cannot find module 'sql-bricks'
sql-bricks-postgres depends on sql-bricks must be installed separately.
fix
Run: npm install sql-bricks sql-bricks-postgres
Upgrade
Version history
0.6.0latest on npm
Audit
Dependencies
sql-bricksrequiredCore SQL builder library extended by this package
Agent activity
15 hits · last 30 days
node
12
Meta
2
OpenAI (training)
1
Resources
sql-bricks-postgres — npm install sql-bricks-postgres · libregistry