All files / src/database connection.js

72.72% Statements 8/11
25% Branches 2/8
50% Functions 1/2
72.72% Lines 8/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 247x 7x   7x           7x 7x 7x       7x             7x  
const { Pool } = require('pg');
const config = require('../config');
 
const pool = new Pool({
  connectionString: config.databaseUrl,
  ssl: config.env === 'production' ? { rejectUnauthorized: false } : false
});
 
// Test database connection
pool.on('connect', () => {
  Eif (config.logLevel !== 'silent') {
    console.info('Connected to MerchantsOfHope-SupplyANdDemandPortal database');
  }
});
 
pool.on('error', (err) => {
  if (err.code === '57P01' || err.message?.includes('terminating connection')) {
    return;
  }
  console.error('Database connection error:', err);
});
 
module.exports = pool;