pgsqwell is an immutable SQL template tag library for PostgreSQL, currently at version 6.0.1. It provides tagged template literals (sql, sqlPart) and helpers (escapeSQLIdentifier, joinSQLValues) for safe SQL construction without risk of injection. Unlike alternatives (e.g., node-postgres template libraries), it emphasizes immutability and separation of concerns: use `sql` for full statements and `sqlPart` for subparts. It ships TypeScript declarations and requires Node >=24.14.0. The library is actively maintained with a focus on correctness and composability.
npm install pgsqwellNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates building a SELECT query with parameterized value, conditional LIMIT using sqlPart, identifier escaping, IN-list via joinSQLValues, and query composition via UNION.
Upgrade Node.js to 24.14.0 or later, or pin to pgsqwell 5.x if using older Node.
Use import syntax or dynamic import() in CommonJS projects. Switch to pgsqwell@5 if CJS required.
Use sql for full statements, sqlPart only for subparts (e.g., conditions, clauses).
Test generated query strings manually or use pgsqwell-mock for testing.
Add "type": "module" to package.json or use dynamic import().
Use import { sql, sqlPart } from 'pgsqwell' instead of import sql from 'pgsqwell'.Use escapeSQLIdentifier('tablename') inside the template literal.