How to use the pg.native.Pool 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 Ameobea / tickgrinder / mm / db.js View on Github external
FROM ${table} WHERE tick_time > ${start_time} AND tick_time < ${end_time};`;
        client.query(query, [], (err, res)=>{
          done();

          if(err) {
            r(console.error('error running query', err));
          } else {
            f(res.rows);
          }
        });
      });
    });
  }
};

var pool = new pg.Pool(pool_conf).on('error', function (err, client) {
  console.error('idle client error', err.message, err.stack);
});

var Db = {
  pool: pool,
  accessors: accessors,
};

module.exports = Db;
github NLeSC / spot / server / server-postgres.js View on Github external
function setConnectionString (s) {
  var c = parseConnection(s);

  pool = new pg.Pool(c);
  pool.on('error', function (err, client) {
    console.error('idle client error', err.message, err.stack);
  });
}
github inventid / iaas / src / databases / postgresql.js View on Github external
export default function postgresql() {
  const configs = {
    user: config.get('postgresql.user'),
    database: config.get('postgresql.database'),
    password: config.get('postgresql.password'),
    host: config.get('postgresql.host'),
    port: 5432,
    max: poolSize,
    idleTimeoutMillis: 30000
  };

  const pool = new native.Pool(configs);

  pool.on('error', function (err) {
    log('error', `idle client error ${err.message} ${err.stack}`);
  });

  async function isDbAlive() {
    const testQuery = 'SELECT 1';
    const metric = timingMetric(DATABASE, {tags: {sqlOperation: 'isDbAlive'}});
    try {
      const result = await pool.query(testQuery, []);
      return Boolean(result.rowCount && result.rowCount === 1);
    } catch (e) {
      return false;
    } finally {
      metrics.write(metric);
    }