How to use the pg.connect 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 eduardinni / bootlint-online / api / app.js View on Github external
function updateLintCounter(lints) {
  pg.defaults.poolSize = 0; // pooling will be disabled
  pg.connect(conString, function(err, client, done) {
    if(err) {
      return console.error('database connection error', err);
    }

    lints.forEach(function(lint) {
      client.query('UPDATE lints SET count = count + 1 WHERE id = $1', [lint.id], function(err, result) {
        done();
        if(err) {
          return console.error('error running query', err);
        }
      });
    });
    pg.end();
  });
}
github jugglingdb / postgres-adapter / lib / postgres.js View on Github external
PG.prototype.query = function(sql, callback) {
    const time = Date.now();
    const log = this.log;
    pg.connect(this.settings, function(err, client, done) {
        if (err) {
            return callback(err);
        }
        client.query(sql, function(err, data) {
            if (log) log(sql, time);
            // harish2704: when we call done, client is return back to pool
            // so that it can be reused again. It's necessary for working with pools
            done();
            callback(err, data ? data.rows : null);
        });
    });
};
github numtel / mysql-live-select / test / load / setup-interactive.es6 View on Github external
var clientPromise = new Promise((resolve, reject) => {
  console.time('Connected to database server')
  pg.connect(options.conn, (error, client, done) => {
    console.timeEnd('Connected to database server')
    if(error) return reject(error)
    clientDone = done
    resolve(client)
  })
}).catch(reason => console.error(reason))
github sensedata / space-telemetry / server / db.js View on Github external
function selectStatsByIdx(idx, cb) {

  pg.connect(psql, function (err, client, done) {

    if (err) {

      console.error('Error requesting postgres client', err);

      notify.error(err);

      return cb(err);
    }

    client.query('select avg(lag_avg) as lag_avg,' +
      ' avg(lag_stddev) as lag_stddev, sum(tick_count) as tick_count, avg(value_avg) as val_avg,' +
      ' avg(value_stddev) as val_stddev from telemetry_session_stats where idx = $1',
      [idx],
      function (err2, res) {
github KevinEverywhere / bob-angular / dist / app / temp.js View on Github external
var pg = require('pg');
console.log("process.env.DATABASE_URL=" + process.env.DATABASE_URL)
pg.connect(process.env.DATABASE_URL, function(err, client) {
  var query = client.query('SELECT * FROM country');

  query.on('row', function(row) {
    console.log(JSON.stringify(row));
  });
});
github GreenInfo-Network / caliparks.org / bin / invalidate-flickr.js View on Github external
var unlockPhoto = function(id, callback) {
  callback = callback || function(err) {
    if (err) {
      console.warn(err.stack);
    }
  };

  return pg.connect(DATABASE_URL, function(err, client, done) {
    if (err) {
      return callback(err);
    }

    var query = "UPDATE flickr_photos SET locked_at = NULL WHERE id = $1";

    return client.query(query, [id], function() {
      done();

      return callback.apply(null, arguments);
    });
  });
};
github chrisprice / t-d3fc / server / src / db.js View on Github external
new Promise((resolve, reject) => {
    pg.connect(conString, (error, client, done) => {
      if (error) {
        winston.warn('Failed to retrieve client from pool', error);
        return reject(error);
      }
      client.query(sql, args, (error, result) => {
        //call `done()` to release the client back to the pool
        done();
        if (error) {
          winston.warn('Failed to perform query', sql, error);
          return reject(error);
        }
        resolve(result.rows.map((r) => r.status));
      });
    });
  });
github keithwhor / nodal / core / required / db / adapters / postgres.js View on Github external
createTransaction(callback) {

    pg.connect(this._config, (err, client, complete) => {

      if (err) {
        return callback(err);
      }

      this.beginClient(client, (err) => {

        if (err) {
          return callback(err);
        }

        return callback(null, new Transaction(this, client, complete));

      });

    });
github votinginfoproject / Metis / app.js View on Github external
});

http.createServer(app).listen(config.web.port, function () {
  logger.info('Express server listening on port ' + config.web.port);
});

var pg = require('pg');
var connString = "postgres://" + process.env.DB_ENV_POSTGRES_USER +
                 ":" + process.env.DB_ENV_POSTGRES_PASSWORD +
                 "@" + process.env.DB_PORT_5432_TCP_ADDR +
                 ":" + process.env.DB_PORT_5432_TCP_PORT +
                 "/" + process.env.DB_ENV_POSTGRES_DATABASE +
                 "?application_name=dashboard";
process.env.DATABASE_URL = connString;

pg.connect(connString, function(err, client, done) {
  if(err) {
    return logger.error('Could not connect to PostgreSQL. Error fetching client from pool: ', err);
  }

  logger.info('Connected to PostgreSQL. May your queries terminate before a 3 minute timeout.');
});
github hardware / ovh-availability / migrations / 003-add-phone.js View on Github external
exports.down = function( next ) {

    pg.connect(process.env.DATABASE_URL, function( dbErr, client, done ) {

        client.query('ALTER TABLE requests DROP COLUMN phone', function( err, result ) {
            next();
        });

    });

};