Created
November 8, 2012 01:16
-
-
Save switz/4035781 to your computer and use it in GitHub Desktop.
How to expose and implement a basic DerbyJS query.
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
// add in app/index.js | |
get('/:year', function(page, model, params) { | |
var year = params.year; | |
var usersQuery = model.query('users').bornOn(year); | |
model.fetch(usersQuery, function (err, users) { | |
// users is a scoped model | |
console.log(users.get()); // prints the results of the query | |
page.render() | |
}); | |
}); |
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
// add in server/index.js | |
// users is the mongodb collection | |
// bornOn is name of the function we expose to the client | |
store.query.expose('users', 'bornOn', function(year) { | |
// birthyear is the mongodb field | |
return this.where('birthyear').equals(year); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
store.query.expose('user', 'bornOn', function() {
return this;
})
get('/:year?', function(page, model, params) {
var year = params.year;
var usersQuery = model.query('user').bornOn();
console.log(year);
model.fetch(usersQuery, function (err, users) {
// users is a scoped model
});
});