import { Pool } from 'pg';

// Create a new pool using individual environment variables
// For cPanel, these will be set in the Node.js app environment variables
const pool = new Pool({
  host: process.env.DB_HOST,
  port: parseInt(process.env.DB_PORT || '5432', 10),
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  // If you are connecting via SSL, uncomment the following lines:
  // ssl: {
  //   rejectUnauthorized: false
  // }
});

export const query = (text: string, params?: any[]) => {
  return pool.query(text, params);
};

export default pool;
