0.0.2 • Published 8 years ago
pg-sql-tag v0.0.2
pg-sql-tag
A pg plugin for sql-tag, combinining the elegance of tagged sql query strings with the convenience and safety of pg.query
.
Status
This module has been deprecated in favour of sql-tag@^1.0.0, which is now able to handle pg
queries without requiring any modification to pg.query
.
Installation
Install the package via npm
:
$ npm install pg-sql-tag
Usage
var pg = require('pg');
var sql = require('sql-tag');
// Wrap `pg` in order to support queries
// generated by the `sql` tag.
require('pg-sql-tag')(pg);
// Use expressions inside placeholders to build elegant
// and readable queries.
pg.query(sql`SELECT * FROM "Foo" WHERE id = ${ 1 * 2 }`, function(err, result) {
if (err) {
throw err;
}
console.log(result);
});
// You can even use function calls inside expressions.
var obj = { foo: 'bar' }
pg.query(sql`UPDATE "Foo" SET biz = ${ JSON.stringify(obj) }`, function(err, result) {
if (err) {
throw err;
}
console.log(result);
});
Tests
$ npm test
License
MIT