Skip to content

Instantly share code, notes, and snippets.

@ericvanjohnson
Forked from chartjes/gist:1995202
Created March 7, 2012 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericvanjohnson/1995998 to your computer and use it in GitHub Desktop.
Save ericvanjohnson/1995998 to your computer and use it in GitHub Desktop.
var http = require('http');
var pg = require('pg');
var connectionString = "pg://chartjes:********@localhost:5432/ibl_stats";
pg.connect(connectionString, function(err, client) {
if (err) {
console.log(err);
} else {
http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/html'});
response.write('<h1>Transactions</h1>');
var q= "SELECT * " +
"FROM transaction_log " +
"WHERE log_entry LIKE 'Trades%' " +
"ORDER BY trans_id DESC " +
"LIMIT 10";
client.query(q, function(err, result) {
if (err) {
console.log(err);
} else {
response.write('<table>');
for (var i=0; i < result.rows.length; i++) {
response.write('<tr>');
response.write('<td>' + result.rows[i].trans_id + '</td>');
response.write('<td>' + result.rows[i].log_entry + '</td>');
response.write('</tr>');
}
response.write('</table>');
response.end();
}
});
}).listen(8080, "localhost");
console.log('Server running at http://127.0.0.1:8080/');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment