pg-named
v1.0.3
Published
Named parameters for node-postgres.
Downloads
7
Readme
pg-named
Named parameters for node-postgres. Kudos to: https://github.com/bwestergard/node-postgres-named and the refactored https://github.com/jars/node-postgres-named.
Before:
client.query('SELECT name FROM person WHERE name = $1 AND tenure <= $2 AND age <= $3', ['Ursus', 2.5, 24]).then(console.log);
After:
client.query('SELECT name FROM person WHERE name = :name AND tenure <= :tenure AND age <= :age', {'name': 'Ursus', 'tenure': 2.5, 'age': 24}).then(console.log);
Placeholders must begin with :
or $
and can contain only alphanumerics, underscores, and dashes.
Usage
import pg from 'pg';
import pgNamed from 'pg-named';
pgNamed(pg);