Postgres Parameters
pg-parameters
is a postgres client library that supports queries with named parameters.
The pg
module supports parameterized queries, however, the queries need to be defined using ordinal parameters ($1
, $2
, etc.), and the parameters must be passed in as an array. The purpose of this library is enable queries to be defined and executed more intuitively using named parameters.
This library uses parameter names preceded by a colon (:
), example: :parameter_name
.
Explicitly named parameters:
const rows = await client;
Instead of:
const rows = await client;
Installation
Installation is done via npm
. Example:
npm install --save pg-parameters
Other features
Some of the other features include:
- table insertion using JavaScript objects
- return
rows
/row
directly fromquery
/querySingle
methods- the existing
pg
result is available using theexecute
method
- the existing
- transactions
typescript
definitions
Example
; const client = host: 'localhost' user: 'postgres' password: '<password>' database: 'postgres'; { // create new table await client; // insert new record const newRecord = await client; console; // select new record const record = await client; console; // select multiple records const records = await client; console;} ;