Skip to content

Instantly share code, notes, and snippets.

@michaelklishin
Forked from ciberch/mysql.js
Created June 6, 2012 05:27
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 michaelklishin/2880071 to your computer and use it in GitHub Desktop.
Save michaelklishin/2880071 to your computer and use it in GitHub Desktop.
Activity Query with Relational DB
// no, node.js does not suffer from the callback spaghetti. Never.
Bug
.select('createdAt', 'creatorId', 'name', 'url', 'description')
.page(0, 10)
.order('createdAt DESC')
.all(function(err, bugs) {
Commit
.select('createdAt', 'creatorId', 'name', 'url', 'description')
.page(0, 10)
.order('createdAt DESC')
.all(function(err, commits) {
// coalesce
ordered = coalesce(bugs, commits, 10);
uniqueUsers = findUniqueUsers(ordered);
uniqueProjects = findUniqueProjects(ordered);
User
.select('id', 'name', 'url', 'avatar_url')
.where({ 'id.in': uniqueUsers })
.all(function(err, users) {
Project
.select('id', 'name', 'url', 'avatar_url')
.where({ 'id.in': uniqueProjects })
.all(function(err, projects) {
// finally, now correlate all the data back together
var activities = [];
//...
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment