Created
July 1, 2016 02:39
-
-
Save bambooom/312c137a6cd0b99d6dc8bd0cbd137ae7 to your computer and use it in GitHub Desktop.
async.parallel multiple sequelize queries
This file contains 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
async.parallel({ | |
card_count: function (cb) { | |
db | |
.Card | |
.findAll({ | |
where: {course_id: 'some id'} | |
}) | |
.then(function (results) { | |
var t = []; | |
results.forEach(function (result) { | |
var e = {}; | |
e['name'] = result.name; | |
e['order_code'] = result.order_code; | |
t.push(e); | |
}) | |
cb(null, t); | |
}); | |
}, | |
pack_count: function (cb) { | |
db | |
.Pack | |
.findAll({ | |
where: {course_id: 'some other id'} | |
}) | |
.then(function (results) { | |
var s = []; | |
results.forEach(function (result) { | |
var e = {}; | |
e['name'] = result.name; | |
e['order_code'] = result.order_code; | |
s.push(e); | |
}) | |
cb(null, s); | |
}); | |
} | |
}, function (err, results) { | |
var card_count = results.card_count; | |
var pack_count = results.pack_count; | |
// results is now { "card_count": t, "pack_count": s } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment