Skip to content

Instantly share code, notes, and snippets.

@bambooom
Created July 1, 2016 02:39
Show Gist options
  • Save bambooom/312c137a6cd0b99d6dc8bd0cbd137ae7 to your computer and use it in GitHub Desktop.
Save bambooom/312c137a6cd0b99d6dc8bd0cbd137ae7 to your computer and use it in GitHub Desktop.
async.parallel multiple sequelize queries
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