JCKalt / General-Work

Modeling database
0 stars 0 forks source link

Update eyedro calls for new lib/db.js that shares. #173

Closed JCKalt closed 3 months ago

JCKalt commented 3 months ago

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;