From 9a692ed6525aa66d9eb444b624c2fe74f3bb3c4e Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Tue, 6 Oct 2020 20:52:48 -0400 Subject: [PATCH] Get the client working as expected with pg 8 --- lib/document_stores/postgres.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/document_stores/postgres.js b/lib/document_stores/postgres.js index dbb471c..bda7e83 100644 --- a/lib/document_stores/postgres.js +++ b/lib/document_stores/postgres.js @@ -1,7 +1,7 @@ /*global require,module,process*/ -var postgres = require('pg'); var winston = require('winston'); +const {Client} = require('pg'); // create table entries (id serial primary key, key varchar(255) not null, value text not null, expiration int, unique(key)); @@ -64,13 +64,17 @@ PostgresDocumentStore.prototype = { // A connection wrapper safeConnect: function (callback) { - postgres.connect(this.connectionUrl, function (err, client, done) { - if (err) { - winston.error('error connecting to postgres', { error: err }); - callback(err); - } else { - callback(undefined, client, done); - } + const client = new Client({connectionString: this.connectionUrl}); + const connectionPromise = client.connect(); + + const done = () => {}; + + connectionPromise.then(() => { + callback(undefined, client, done); + }).catch((error) => { + console.log(error); + winston.error('error connecting to postgres', {error}); + callback(error); }); }