Copying over from WrenchBoradWeb to new repository

This commit is contained in:
2022-05-07 23:20:17 -04:00
commit 6543a2f6c7
18 changed files with 848 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
/**
* @file
* Configures the database connection
*/
const { Pool, Client } = require('pg');
const logger = require('./logger');
//const connectionString = 'postgresql://wrenchboard:wrenchboard@10.10.10.23:5432/wrenchboard';
const connectionString = process.env.POSTGRE_URL;
const postgres = new Pool({
connectionString,
});
postgres.on('connect', client => {
logger.info('Connected to Database');
});
postgres.on('acquire', client => {
logger.info('Client is checked out from the DB connection pool');
});
postgres.on('remove', client => {
logger.info('Client is closed & removed from the DB connection pool');
});
postgres.on('error', (err, client) => {
logger.error(err);
});
// Connect to PostgreSQL
postgres.connect((err, client, release) => {
logger.info(connectionString);
if (err) {
logger.error('Error acquiring client', err.stack);
return null;
}
client.query('SELECT NOW()', (err, result) => {
release();
if (err) {
logger.error('Error executing query', err.stack);
return nul;
}
logger.info(result.rows);
});
});
module.exports = postgres;