Created
May 22, 2012 18:20
-
-
Save ciberch/2770735 to your computer and use it in GitHub Desktop.
Activity Query with Relational DB
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
User.hasMany("bugs", Bug, "creatorId"); | |
Bug.belongsTo("user", User, "creatorId"); | |
Project.hasMany("bugs", Bug, "projectId"); | |
Bug.belongsTo("project", Project, "projectId"); | |
User.hasMany("commits", Commit, "creatorId"); | |
Commit.belongsTo("user", User, "creatorId"); | |
Project.hasMany("commits", Commit, "projectId"); | |
Commit.belongsTo("project", Project, "projectId"); | |
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