Example #1
0
beforeEach(done => {
  pool.end().then(() => {
    testUtilities.reset();
    pool = new pg.Pool(config);
    User._set(pool);
    done();
  });
});
export const createPoolConnection = (conf) => {
    const pool = new Pool(conf);
    return {
        query(q) {
            return pool.query(q);
        },
        connect() {
            return pool.connect();
        },
        stop() {
            return pool.end();
        }
    };
};
Example #3
0
 close () {
   this.pool.end()
 }
Example #4
0
 dispose: function dispose() {
     return pool.end();
 }
Example #5
0
 .catch((err) => {
   console.log(err);
   pool.end();
 });
Example #6
0
 .then((res) => {
   console.log(res);
   pool.end();
 })
Example #7
0
 .catch((err) => {
   pool.end();
   return res.status(400).send(err);
 })
Example #8
0
 .then((res) => {
   pool.end();
   const rows = res.rows;
   return res.status(201).send(rows[0]);
 })
Example #9
0
    idleTimeoutMillis: config.pool_timeout
})

/**
 * pg query doesn't throw the original exception when the catch is not used
 * not sure what is causing this
 * @param  {Error} err Error to throw
 * @return {undefined}
 */
function rethrow (err) {
    throw err
}

module.exports = {
    disconnect () {
        pool.end().catch(log.error)
    },

    getClient () {
        return pool.connect()
    },

    async query (query, values, client) {
        if (query && query.constructor === Array && !values) {
            const built = buildQuery(query)

            query = built.text
            values = built.values
            log.trace({ query, values }, 'QUERY')
        }
Example #10
0
const pg = require('pg')
const config = require('../../../config.json')

const pool = new pg.Pool(config.db)

pool.on('error', err => {
  /* eslint-disable */
  console.error('idle client error', err.message, err.stack)
})

export default {
  query(text, values, callback) {
    // log queries in dev environment
    if (process.env.NODE_ENV !== 'production') {
      /* eslint-disable */
      console.log('query: ', text)
      if (values) {
        console.log('query with values: ', values)
      }
    }

    return pool.query(text, values, callback)
  },
  connect(fn) {
    return pool.connect(fn)
  },
  end() {
    return pool.end()
  }
}
Example #11
0
File: db.js Project: timgit/pg-boss
 close(){
   return !this.pool.ending ? this.pool.end() : Promise.resolve(true);
 }
Example #12
0
const backend = require('backend.js');
const pg = require('pg');

const sample = loadJSON('sample.json');

const users = {
  database: cilph,
  host: 'localhost',
  user: 'KupidoExportLLC'
};

const pool = new pg.Pool(users);

pool.connect(function(err, client, done){
  client.query(`INSERT INTO users(first_name, last_name, email, message) VALUES ("$1, $2, $3, $4", {backend.info.name, backend.info.last, backend.info.email})`, function(err, result){
    console.log(err);
    console.log(result.rows);
    done();
  });

});

pool.end();
 this.on('finish', () => {
   if (this.pool) {
     return this.pool.end()
   }
 })