Skip to content

Instantly share code, notes, and snippets.

@switz
Created November 8, 2012 01:16
Show Gist options
  • Save switz/4035781 to your computer and use it in GitHub Desktop.
Save switz/4035781 to your computer and use it in GitHub Desktop.
How to expose and implement a basic DerbyJS query.
// 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()
});
});
// 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);
});
@sgarbesi
Copy link

sgarbesi commented Nov 8, 2012

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

console.log(users.get()); // prints the results of the query

});

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment