Registry / database / psqljs

psqljs

JSON →
library0.0.6jsnpmunverified

A minimal SQL generator for Node.js and PostgreSQL that builds parameterized queries with support for SELECT, INSERT, UPDATE, DELETE, WHERE, ORDER BY, LIMIT/OFFSET, and RETURNING clauses. Version 0.0.6 is the current release; the library has a low release cadence and is not actively developed. It generates query objects with 'text' and 'values' properties compatible with the 'pg' module. Compared to alternatives like Squel or Knex, psqljs is extremely minimal with no dependencies but lacks TypeScript support, join building, raw SQL escape hatches, and advanced features.

npm install psqljs
INSTALL
IMPORT
SIG · PSQLJS
P
psqljs
databasejavascriptv0.0.6
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
import sql from 'psqljs'
const { sql } = require('psqljs')
The exported default is a function. In CommonJS, use require('psqljs') which returns the function directly.
select, insert, update, delete
const sql = require('psqljs') sql.select().from('users').toQuery()
const { select } = require('psqljs') select().from('users').toQuery()
All query builders are methods on the default exported function. Destructuring will not work.
toQuery()
sql.select().from('users').toQuery()
sql.select().from('users').build()
The method is named toQuery(), not build() or toString(). It returns an object { text, values }.

Shows basic usage of psqljs to generate SELECT, INSERT, UPDATE, and DELETE parameterized queries.

const sql = require('psqljs'); // SELECT const query1 = sql.select().from('users').where('id = $1', 1).toQuery(); console.log(query1); // { text: 'select * from users where id = $1', values: [1] } // INSERT const query2 = sql.insert('users', { firstName: 'Johnny', lastName: 'Appleseed' }).returning().toQuery(); console.log(query2); // { text: 'insert into users (firstName, lastName) values ($1, $2) returning *', values: ['Johnny', 'Appleseed'] } // UPDATE const query3 = sql.update('users', { salary: 'billions' }).where('job = $1', 'CEO').toQuery(); console.log(query3); // { text: 'update users set salary = $1 where job = $2', values: ['billions', 'CEO'] } // DELETE const query4 = sql.delete('users').where('firstName = $1', 'Johnny').toQuery(); console.log(query4); // { text: 'delete from users where firstName = $1', values: ['Johnny'] } // Execute with pg: // const { Client } = require('pg'); // const client = new Client(); // await client.connect(); // const res = await client.query(query1);
Debug
Known issues
gotchaNo TypeScript support: the package does not ship any type definitions.
fix
Define your own types or use @ts-ignore when importing.
affects: >=0.0.1
gotchaNo support for JOINs or subqueries.
fix
Use another library like Knex or Squel if you need JOINs.
affects: >=0.0.1
deprecatedThe package has not been updated since 2016 and has no maintenance history.
fix
Consider migrating to a maintained alternative like Knex.js or pg-promise.
affects: >=0.0.1
gotchaQuery builder methods always return a builder object; toQuery() must be called to generate the final query object.
fix
Ensure you call .toQuery() at the end of the chain.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: sql.select is not a function
CommonJS import incorrectly destructured the module.
fix
Use const sql = require('psqljs'); then sql.select().
TypeError: Cannot read property 'from' of undefined
Forgot to call .toQuery() on the builder chain.
fix
Add .toQuery() at the end: sql.select().from('users').toQuery()
Cannot find module 'psqljs'
Package not installed or named incorrectly.
fix
Run npm install psqljs --save and ensure package.json includes it.
Upgrade
Version history
0.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
10
Resources
packagepsqljs
psqljs — npm install psqljs · libregistry