summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--index.js36
1 files changed, 28 insertions, 8 deletions
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