File size: 438 Bytes
eeb3436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const { Pool } = require("pg");

function createDbPool(config, logger) {
  const pool = new Pool(config.db.pg);

  pool.on("error", (error) => {
    logger.error("Unexpected PostgreSQL pool error", { error: error.message });
  });

  return pool;
}

async function verifyDbConnection(pool) {
  const result = await pool.query("SELECT NOW() AS now");
  return result.rows[0];
}

module.exports = {
  createDbPool,
  verifyDbConnection,
};