const { Pool } = require('pg');

const config = process.env.DATABASE_URL
  ? { connectionString: process.env.DATABASE_URL }
  : {
      host: process.env.PGHOST || 'localhost',
      port: process.env.PGPORT ? Number(process.env.PGPORT) : 5432,
      user: process.env.PGUSER || 'pads',
      password: process.env.PGPASSWORD || 'pads',
      database: process.env.PGDATABASE || 'pads',
    };

const pool = new Pool(config);

module.exports = {
  query: (text, params) => pool.query(text, params),
};
