Created
July 5, 2013 09:20
-
-
Save pphetra/5933230 to your computer and use it in GitHub Desktop.
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 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