Registry / database / pg-escape-browser

pg-escape-browser

JSON →
library0.1.0jsnpmunverified

Sprintf-style Postgres query formatting and escape helper functions. Version 0.1.0 is a simple, lightweight library for building safe SQL queries without stored procedures. It provides string, ident, literal, and dollar-quoted string escaping via format specifiers (%s, %I, %L, %Q). Unlike parameterized queries, it generates plain SQL strings, useful for dynamic query construction. Released under MIT license.

npm install pg-escape-browser
INSTALL
IMPORT
SIG · PG-ESCAPE-BROWSER
P
pg-escape-browser
databasejavascriptv0.1.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.

escape
import escape from 'pg-escape'
const escape = require('pg-escape')
Default import works; named imports are not supported.
escape.string
escape.string(val)
escape.string`${val}`
Escape methods are attached to the default export.
escape.ident
escape.ident(val)
escape.ident`${val}`
Use as function call, not tagged template.

Demonstrates basic usage: escaping an identifier and a literal in a SQL INSERT query.

import escape from 'pg-escape'; const sql = escape('INSERT INTO %I VALUES(%L)', 'books', "O'Reilly"); console.log(sql); // INSERT INTO books VALUES('O''Reilly')
Debug
Known issues
deprecatedThis package is unmaintained and no longer recommended.
fix
Use parameterized queries (e.g., pg's built-in $1 syntax) or a modern library like slonik or kysely.
affects: >=0.0.0
gotchaNot parameterized: the output is a plain string, which can still lead to SQL injection if misused.
fix
Always use escape functions for all user input; avoid direct string concatenation.
affects: >=0.0.0
gotchaNull handling: %s treats null as empty string, %L treats null as literal NULL, %I throws an error on null.
fix
Ensure identifiers are never null; use conditional logic if needed.
affects: >=0.0.0
gotchaNot compatible with ES module imports in older Node versions without bundling.
fix
Use CommonJS require or a bundler for ESM support.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: escape is not a function
Importing incorrectly as named export instead of default.
fix
Use `import escape from 'pg-escape'` or `const escape = require('pg-escape')`.
Error: Cannot find module 'pg-escape'
Package not installed or resolved incorrectly.
fix
Run `npm install pg-escape`.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
pg-escape-browser — npm install pg-escape-browser · libregistry