Registry / database / pg-template-tag

pg-template-tag

JSON →
library0.1.2jsnpmunverified

An ESM template tag function for building parameterized PostgreSQL queries compatible with node-postgres (pg). Version 0.1.2 is stable, but the package is in maintenance mode with no active development. It provides nesting, reusable query fragments, and a .join helper, which differentiates it from raw string interpolation or other query builders by safely separating SQL text from values.

npm install pg-template-tag
INSTALL
IMPORT
SIG · PG-TEMPLATE-TAG
P
pg-template-tag
databasejavascriptv0.1.2
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 SQL from 'pg-template-tag'
const SQL = require('pg-template-tag')
ESM-only; CJS require will fail since package is type: module.
SQL
import SQL from 'pg-template-tag'
import { SQL } from 'pg-template-tag'
The package exports a single default tagged template function, not a named export.
default export
import SQL from 'pg-template-tag'; SQL.join()
import { join } from 'pg-template-tag'
SQL.join is a static method on the default export, not a separate named export.

Shows basic usage: import, build a parameterized query with template literal, and execute via node-postgres.

import SQL from 'pg-template-tag'; import pg from 'pg'; const pool = new pg.Pool(); async function getUser(id) { const query = SQL`SELECT * FROM users WHERE id = ${id}`; const result = await pool.query(query); return result.rows[0]; } async function main() { const user = await getUser(1); console.log(user); } main().catch(console.error);
Debug
Known issues
gotchaValues array reuses parameter indexes for identical fragments; unexpected sharing may occur.
fix
Use SQL.join or clone fragments if you need independent parameter positions.
affects: >=0.0.0
gotchaThe package is ESM-only; using require() throws an error.
fix
Switch to import syntax or use dynamic import.
affects: >=0.0.0
deprecatedPackage is in maintenance mode; no new features or bug fixes expected.
fix
Consider alternatives like slonik, squel, or raw pg parameterization.
affects: >=0.1.1
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
Package is ESM-only; CJS require is not allowed.
fix
Use import SQL from 'pg-template-tag' or enable ESM in your project.
TypeError: SQL is not a function
Attempting to import { SQL } instead of default import.
fix
Use import SQL from 'pg-template-tag' (no braces).
Cannot read properties of undefined (reading 'join')
Calling SQL.join() but SQL is undefined due to incorrect import syntax.
fix
Ensure default import: import SQL from 'pg-template-tag'.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
pgoptionalPeer dependency: node-postgres client used to execute the generated query objects
Agent activity
2 hits · last 30 days
node
2
Resources
pg-template-tag — npm install pg-template-tag · libregistry