From b1033e1caa7755abcd616a1c25f7ec4642821382 Mon Sep 17 00:00:00 2001 From: myk bilokonsky Date: Mon, 10 Apr 2017 00:24:54 +0200 Subject: removed pool, just have a single default-setting setup now --- index.js | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 301e69e..e447e52 100644 --- a/index.js +++ b/index.js @@ -21,14 +21,34 @@ var config = { idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed }; -const pool = new pg.Pool(config); +var pg = require('pg'); + +// instantiate a new client +// the client will read connection information from +// the same environment variables used by postgres cli tools +var client = new pg.Client(); + +function cycle() { + // connect to our database + client.connect(function (err) { + if (err) throw err; -pool.query(query, [], function(err, res) { - if(err) { - return console.error('error running query', err); - } + // execute a query on our database + client.query(query, [], function (err, result) { + if(err) { + return console.error('error running query', err); + } - res.rows.forEach(function(row) { - console.dir(row); + res.rows.forEach(function(row) { + console.dir(row); + }); + + // disconnect the client + client.end(function (err) { + if (err) throw err; + }); + }); }); -}); \ No newline at end of file +} + +cycle(); \ No newline at end of file -- cgit