Created
February 26, 2014 23:20
-
-
Save gregbuehler/9240912 to your computer and use it in GitHub Desktop.
I'm not groking this event stuff...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pg = require('pg'); | |
| var pg_cs = "tcp://gbuehler@localhost/bigbro"; | |
| exports.disconnect = function pg_disconnect() { | |
| pg.end() | |
| }; | |
| exports.pg_query = function pg_query(sql) { | |
| console.log("database.pg_query: %s", sql); | |
| var res = undefined; | |
| pg.connect(pg_cs, function(err, client) { | |
| if (err) throw err; | |
| client.query(sql, function(err, result) { | |
| if (err) throw err; | |
| res = result; | |
| console.log("database.pg_query internal: %j", res); | |
| return res; | |
| }); | |
| }); | |
| console.log("database.pg_query final: ", res); | |
| return res; | |
| }; | |
| exports.pg_req_res_query = function pg_req_res_query(req, res, sql){ | |
| console.log("database.pg_req_res_query: %s", sql); | |
| pg.connect(pg_cs, function(err, client) { | |
| if (err) { | |
| console.log("pg_req_res_query error: %s", err); | |
| throw err; | |
| } | |
| client.query(sql, function(err, result) { | |
| if (err) { | |
| console.log("pg_req_res_query error: %s", err); | |
| throw err; | |
| } | |
| console.log("pg_req_res_query result: %s", result); | |
| if (result) | |
| res.send(result.rows); | |
| }); | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var database = require('../database'); | |
| exports.index = function(req, res){ | |
| var title = 'foo'; | |
| var foo = database.pg_query("select distinct foo from bar"); | |
| res.render('sites', { title: title, foobar: foo }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment