breakhours-transform/services/db.js

26 lines
551 B
JavaScript
Raw Permalink Normal View History

2024-10-03 11:55:18 +00:00
import pkg from 'pg';
import dotenv from 'dotenv';
dotenv.config();
const { Pool } = pkg;
const pool = new Pool({
user: process.env.PSQL_USERNAME,
host: process.env.PSQL_HOSTNAME,
database: process.env.PSQL_DATABASE,
password: process.env.PSQL_PASSWORD,
port: process.env.PSQL_PORT,
});
pool.on('connect', () => {
console.log('Connected to the database');
});
pool.on('error', (err, client) => {
console.error('Unknown database error', err);
process.exit(-1);
});
export const query = (text, params) => pool.query(text, params);