JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 59
  • Score
    100M100P100Q59389F
  • 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-pg query when number of paramters varies.

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

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

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);
 }