Skip to content

Instantly share code, notes, and snippets.

@pphetra
Created July 5, 2013 09:20
Show Gist options
  • Select an option

  • Save pphetra/5933230 to your computer and use it in GitHub Desktop.

Select an option

Save pphetra/5933230 to your computer and use it in GitHub Desktop.
var redis = require('redis');
var client = redis.createClient();
var pg = require('pg');
var async = require('async');
var _ = require('underscore');
var conn = new pg.Client("tcp://erp:erp@localhost/poc");
function getReport(id, callback) {
console.log('getReport ', id);
conn.query('select title from report where id = $1', [id], function(err, result) {
callback(err, {
id: id,
title: result.rows[0].title
});
})
}
function getComment(report, callback) {
conn.query('select id, title from comment where report_id = $1', [report.id], function(err, result) {
report.comments = result.rows;
callback(err, report);
})
}
async.waterfall([
function(callback) {
conn.connect(function(err) {
callback();
});
},
function(callback) {
client.zrange("c1", 0, -1, function(err, results) {
async.mapSeries(results, getReport, callback);
})
},
function(results, callback) {
async.mapSeries(results, getComment, callback);
}
], function(err, results) {
client.quit();
conn.end();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment