From 45a9a42f2e9584ac25f3164d529218c65aa1240e Mon Sep 17 00:00:00 2001
From: jkaplon <jody@kaplon.us>
Date: Thu, 8 Oct 2015 12:05:03 -0400
Subject: [PATCH] Continue Postgres conversion in server.js and templates.

---
 server.js           | 17 +++++++++++------
 views/core-edit.hbs |  8 ++++----
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/server.js b/server.js
index 3227e56..f49fc7c 100644
--- a/server.js
+++ b/server.js
@@ -96,18 +96,23 @@ app.get('/core/edit/:id', function(req, res){
     var coreId = req.params.id;
     console.log("GET /core/edit/" + coreId + ", " + JSON.stringify(d, 4));
 
-    db.all("select coreName, locationDesc from Cores where coreId = ?;", coreId, function(err, rows){
-        if(err !== null) {
-            console.log(err);
-        } else {
-            res.render('core-edit', {values: rows}, function(err, html) {
+    pg.connect(conString, function(err, client, done) {
+        if(err) {
+            return console.error('error fetching client from pool', err);
+        }
+        client.query("select corename, locationdesc from cores where coreid = ($1);", [coreId], function(err, result) {
+            //call `done()` to release the client back to the pool
+            done();
+
+            if(err) { return console.error('error running query', err); }
+            res.render('core-edit', {values: result.rows}, function(err, html) {
                 if(err !== null) {
                     console.log(err);
                 } else {
                     res.send(html);
                 }
             });
-        }
+        });
     });
 });
 
diff --git a/views/core-edit.hbs b/views/core-edit.hbs
index 16f3ed5..0d1154f 100644
--- a/views/core-edit.hbs
+++ b/views/core-edit.hbs
@@ -6,16 +6,16 @@
         <div class="form-group">
             {{label "deviceName" "Edit Device Name:"}}
             {{input "deviceName" coreName class="form-control"}}
-            {{#if values.0.coreName}}
-                <p class="bg-info">* Current value is, {{values.0.coreName}}</p>
+            {{#if values.0.corename}}
+                <p class="bg-info">* Current value is, {{values.0.corename}}</p>
             {{/if}}
         </div>
 
         <div class="form-group">
             {{label "locationDesc" "Edit Location:"}}
             {{input "locationDesc" locationDesc class="form-control"}}
-            {{#if values.0.locationDesc}}
-                <p class="bg-info">* Current value is, {{values.0.locationDesc}}</p>
+            {{#if values.0.locationdesc}}
+                <p class="bg-info">* Current value is, {{values.0.locationdesc}}</p>
             {{/if}}
         </div>