Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const PgClient = require('pg').Client;
- module.exports = function makeHelpers() {
- var hlp = { ctx: null };
- hlp.connectToDatabase = async function (dbCfg){
- const dbClient = new PgClient({
- host : dbCfg.host,
- port : dbCfg.port,
- user: dbCfg.username,
- database: dbCfg.dbname,
- password: dbCfg.password
- });
- hlp.ctx.dbClient = dbClient;
- try {
- await dbClient.connect();
- }
- catch (e) {
- console.error('Could not connect to the Postgres database.');
- console.error(e);
- process.exit(4);
- }
- };
- hlp.helperFunction1 = async function (d){
- let res = hlp.ctx.dbClient.query('..some query..');
- // ...do more work
- return val;
- };
- return hlp;
- };
Add Comment
Please, Sign In to add comment