How to use the pg.js.Client function in pg

To help you get started, we’ve selected a few pg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brianc / node-pg-query-stream / test / issue-3.js View on Github external
it('works', function(done) {
    var client1 = new pg.Client()
    client1.connect()
    var client2 = new pg.Client()
    client2.connect()

    var qr = new QueryStream("INSERT INTO p DEFAULT VALUES RETURNING id")
    client1.query(qr)
    var id = null
    qr.on('data', function(row) {
      id = row.id
    })
    qr.on('end', function () {
      client2.query("INSERT INTO c(id) VALUES ($1)", [id], function (err, rows) {
        client1.end()
        client2.end()
        done(err)
      })
    })
  })
github brianc / node-pg-query-stream / test / issue-3.js View on Github external
before(function(done) {
    var client = new pg.Client()
    client.connect()
    client.on('drain', client.end.bind(client))
    client.on('end', done)
    client.query('create table IF NOT EXISTS p(id serial primary key)')
    client.query('create table IF NOT EXISTS c(id int primary key references p)')
  })
  it('works', function(done) {
github brianc / node-pg-query-stream / test / issue-3.js View on Github external
it('works', function(done) {
    var client1 = new pg.Client()
    client1.connect()
    var client2 = new pg.Client()
    client2.connect()

    var qr = new QueryStream("INSERT INTO p DEFAULT VALUES RETURNING id")
    client1.query(qr)
    var id = null
    qr.on('data', function(row) {
      id = row.id
    })
    qr.on('end', function () {
      client2.query("INSERT INTO c(id) VALUES ($1)", [id], function (err, rows) {
        client1.end()
        client2.end()
        done(err)
      })
github brianc / node-pg-query-stream / test / helper.js View on Github external
describe(name, function() {
    var client = new pg.Client()

    before(function(done) {
      client.connect(done)
    })

    cb(client)

    after(function(done) {
      client.end()
      client.on('end', done)
    })
  })
}
github didit-tech / FastLegS / lib / pg_setup.js View on Github external
return function query(text, values, cb) {
    var client = new pg.Client(connString);
    //client.connect();
    //if (typeof text === 'object') return client.query(text);
    if (typeof values === 'function') {
      cb = values;
      values = [];
    }
    client.connect(function(err) {
      if (err) return cb(err);
      client.query(text, values, function(err, result) {
        client.end();
        if (err) return cb(err);
        return cb(err, result.rows, result);
      });
    });
  };
};