sql-params

1.0.1 • Public • Published

sql-params

Build Status NPM version

Use anonymous objects instead of arrays when using parametric SQL queries.

Installation

$ npm install sql-params

Usage

var sqlParams = require('sql-params');
 
var sql    = 'select * from user where points > @points and id = @id';
var params = { points: 24, id: 123 };
 
var opts = sqlParams(sql, params);

Returns a hash with the pg-ready parametric SQL string and array of values:

{
  text   : 'select * from user where points > $1 and id = $2',
  values : [24, 123]
}

You can even pass it directly when using the query method with the pg driver:

pg.connect(URL, function(err, client) {
  client.query(sqlParams(sql, params), function(err, result) {
 
    ...
 
  });
});

Testing

$ npm test

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i sql-params

Weekly Downloads

3

Version

1.0.1

License

MIT

Last publish

Collaborators

  • bvalosek