I have the following code where I am using the splice function to pass only the first 10 /JSON objects to the JADE template.
app.get('/index', function(req, res) {
new models.Condos()
.query('orderBy', 'age', 'asc')
.fetch()
.then(function(names) {
var name = names.splice(0,10);
res.render('index', {
names: name.toJSON()
});
});
});
};
Is there any way where i could restrict the query itself to return only the first 10 records instead of splicing the array to do that (use the offset and limit parameters) ?
You can write a knex query to achieve this it will look something like:
You will also need to require knex in your router file.