// Function to create a pool based on the provided config identifier
function createPool(configIdentifier) {
// Base configuration options
let connectionOptions = {
database: process.env[PGDATABASE_${configIdentifier}],
user: process.env[PGUSER_${configIdentifier}],
password: process.env[PGPASSWORD_${configIdentifier}], // Add if necessary
host: process.env[PGHOST_${configIdentifier}],
port: process.env[PGPORT_${configIdentifier}],
};
We have a new way to share lib/db.js as follows:
const { Pool } = require('pg');
// Function to create a pool based on the provided config identifier function createPool(configIdentifier) { // Base configuration options let connectionOptions = { database: process.env[
PGDATABASE_${configIdentifier}
], user: process.env[PGUSER_${configIdentifier}
], password: process.env[PGPASSWORD_${configIdentifier}
], // Add if necessary host: process.env[PGHOST_${configIdentifier}
], port: process.env[PGPORT_${configIdentifier}
], };// Conditionally add SSL configuration const { baseUrl } = require('../../config'); if (baseUrl && baseUrl.startsWith('https')) { connectionOptions.ssl = { rejectUnauthorized: false }; }
// Create and return the pool const pool = new Pool(connectionOptions); return { query: (text, params) => pool.query(text, params), }; }
module.exports = createPool;