node-postgres-named is a utility library designed to introduce named parameter support to the `node-postgres` client by monkeypatching its `query` method. As of its latest release, version 2.4.1 (published in 2018), this package allows developers to write more readable SQL queries using `$name` syntax, which it then translates into the positional `$1`, `$2` parameters required by PostgreSQL. This addresses a deliberate design choice in `node-postgres` to maintain a minimal API consistent with PostgreSQL's native capabilities, which do not inherently support named parameters. Given the absence of updates since 2018, this project is considered abandoned. Consequently, its compatibility with contemporary Node.js versions, recent `node-postgres` releases, and modern JavaScript module systems like ESM is highly uncertain and likely problematic.
npm install node-postgres-namedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import, patch a `pg` client, and then execute a query using named parameters.
Consider migrating to a more modern ORM or query builder that offers named parameter-like functionality natively without monkeypatching, or manually mapping named parameters to positional ones.
Evaluate alternatives for named parameters or query building that are actively maintained and compatible with current ecosystem standards. If forced to use, thorough testing with your specific `node-postgres` and Node.js versions is crucial.
If using ESM, you will need to `import named from 'node-postgres-named'` (with appropriate `package.json` configuration or a build tool) or explicitly use `createRequire` from `module` to load it in an ESM context.
Ensure named parameters strictly adhere to the `$` followed by a letter, then alphanumerics, underscores, or dashes.
Ensure `client` is a valid, unpatched `pg.Client` instance before calling `named.patch(client)`.
Double-check that every named parameter (e.g., `$name`) in your SQL query string has a corresponding key in the `values` object, and vice-versa. Also, verify that `named.patch(client)` was successfully called.
If your project is ESM, consider using a dynamic import (`await import('node-postgres-named')`) or revert to CJS if possible. However, the best long-term solution is to migrate to a maintained library for named parameters or ORM functionality.