0.0.6 • Published 6 years ago

pga-sql v0.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

pga-sql

npm Node.js Build Status Coverage Dependencies Status devDependencies Status MIT licensed

A template tagging function that returns an object compatible with the pg module's querying methods.

Installation

npm install --save pga-sql

Usage

pga-sql provides a template tagging function that returns an object compatible with node-postgres's querying methods and, by extension, pga's query, parallel, and transact methods. Template literal variable interpolation makes writing lengthy parameterized queries much cleaner.

Regular variables may be interpolated as string literals (without applying parameterized filtering from the node-postgres module) by prefixing them with an additional $ character. This is unsafe, and should be used carefully.

Query

const pga = require('pga');
const sql = require('pga-sql');

var db = pga({
  user:     'postgres',
  password: '',
  database: 'postgres',
  host:     'localhost',
  port:     5432,
  max:      10
});

var id = 1;
var table = 'test';
var query = sql`SELECT * FROM $${table} WHERE id = ${id};`;

db.query(query, function(error, result) {
  if (error) {
    return console.error(error);
  }
  console.log(result);
});
0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

7 years ago

0.0.0

7 years ago