JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 75
  • Score
    100M100P100Q59699F
  • License MIT

A small helper to parameterize your node-pg query

Package Exports

  • pg-parameterize

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pg-parameterize) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pg-parameterize

A small helper to parameterize your node-postgres query when number of parameters varies.

pg-paramterize finds ? in your string and replaces them with correct numerical paramters ($1, $2, etc)

SELECT * FROM table WHERE field = ?

becomes

SELECT * FROM table WHERE field = $1

This can be helpful if you're creating your sql string dynamically

Example

function simpleFind(options)
  let text = 'SElECT * FROM houses WHERE available = 1'
  const values = [];
  
  if (options.type) {
    sql += ' AND type = ?'
    values.push(options.type)
  }
  
  if (options.zipcode) {
    sql += ' AND zipcode = ?'
    values.push(options.type)
  }
  
  let q = parameterize(text);
  
  return client.query(text, values);
 }