connect-pg icon indicating copy to clipboard operation
connect-pg copied to clipboard

fix for newer version of node-postgres

Open abhishekmunie opened this issue 11 years ago • 0 comments

Updates to support done(), which releases client back to pool in new node-postgres. https://github.com/brianc/node-postgres#client-pooling

var pg = require('pg');
var conString = "postgres://postgres:1234@localhost/postgres";

pg.connect(conString, function(err, client, done) {
  if(err) {
    return console.error('error fetching client from pool', err);
  }
  client.query('SELECT $1::int AS numbor', ['1'], function(err, result) {
    //call `done()` to release the client back to the pool
    done();

    if(err) {
      return console.error('error running query', err);
    }
    console.log(result.rows[0].numbor);
    //output: 1
  });
});

abhishekmunie avatar Feb 03 '14 16:02 abhishekmunie