Registry / database / pg-query-string

pg-query-string

JSON →
library0.1.7jsnpmunverified

pg-query-string is a small library (v0.1.7, stable) for building PostgreSQL query strings with parameterized values. It is a fork of squel, hardcoded to PostgreSQL, with type coercion and ES6 class-based schema/table constructs. Current version is 0.1.7, no recent updates. Key differentiator: produces both SQL text and parameter arrays for safe execution.

npm install pg-query-string
INSTALL
IMPORT
SIG · PG-QUERY-STRING
P
pg-query-string
databasejavascriptv0.1.7
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.

Table
import { Table } from 'pg-query-string'
const { Table } = require('pg-query-string')
Package is ESM-only. Default export is not available.
Schema
import { Schema } from 'pg-query-string'
import pgqs from 'pg-query-string'
Default import does not exist; use named imports.
Table
const { Table } = await import('pg-query-string')
const Table = require('pg-query-string').Table
For dynamic imports, use ESM dynamic import syntax in Node >= 13.2 or with type: module.

Creates a schema and table with typed columns, then builds an UPDATE query with parameterized values.

import { Schema, Table } from 'pg-query-string'; const schema = new Schema('my_schema'); const table = schema.table('users', { id: 'uuid', username: 'text', active: 'boolean' }); const result = table.update( { active: true }, { id: 1 } ); console.log(result.text); // UPDATE "my_schema".users SET active = $1::boolean WHERE (id = $2::uuid) console.log(result.values); // [ true, 1 ]
Debug
Known issues
gotchaPackage is ESM-only; requires Node >= 13 or a bundler like webpack/esbuild.
fix
Use import syntax or configure bundler to handle ESM.
affects: >=0.1.0
deprecatedThe package has not been updated since 2019 and may have unpatched security issues.
fix
Consider using 'pg' or 'knex' for more maintained query building.
affects: >=0.1.0
gotchaObject literals for insert/update produce $1, $2, etc. in the order of object keys, which is non-deterministic in older JavaScript engines.
fix
Use Map or arrays to guarantee order.
affects: >=0.1.0
gotchaSchema and table names are quoted with double quotes, which are case-sensitive in PostgreSQL. Ensure lowercase names.
fix
Use snake_case for schema/table names to avoid quoting issues.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: (0 , _pgQueryString.Table) is not a constructor
Using default import instead of named import.
fix
Change to: import { Table } from 'pg-query-string'
SyntaxError: Cannot use import statement outside a module
Using ESM import in a CommonJS file without 'type': 'module'.
fix
Add 'type': 'module' to package.json or use dynamic import().
Missing initializer in const declaration
Using const without assigning import result.
fix
Correct import: import { Schema } from 'pg-query-string'
Upgrade
Version history
0.1.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
pg-query-string — npm install pg-query-string · libregistry