
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
bookshelf-paginator
Advanced tools
bookshelf-paginator allow paginate your models with ease.
This library depends of bookshelf-model-loader
and bookshelf
.
This library help you create paginated lists, simple connected without adding extra data to the response body. Allowing popular response headers easily, the headers are customizables, here the complete default options
{
headers: {
total: 'X-Total',
limit: 'X-Limit',
offset: 'X-Offset'
},
queryStrings: {
limit: 'limit',
offset: 'offset'
},
limit: 25,
offset: 0,
filterBy: [],
sortBy: 'id',
comp: '='
}
$ npm install --save bookshelf-paginator
var Language = Models.Bookshelf.Model.extend({
tableName: 'language'
});
var Person = Models.Bookshelf.Model.extend({
tableName: 'person',
languages: function() {
return this.belongsToMany('Language', 'person_speaks_language', 'person_id', 'language_id');
},
getLanguages: function() {
return this.related('languages');
},
getPrimaryLanguage: function() {
if (this.getLanguages().size()) {
return this.getLanguages().at(0).get('name');
}
},
toJSON: function() {
return {
fullname: [this.get('firstname'), ' ', this.get('lastname')].join(' ').trim(),
primaryLanguage: this.getPrimaryLanguage()
};
}
});
var Paginator = require('bookshelf-paginator');
var paginator = new Paginator('Person', {
limit: 15,
filterBy: ['firstname', 'lastname']
});
paginator.paginate().then(function(paginator) {
paginator.getData(); // return a person collection
paginator.getTotal(); // return total register
paginator.getOffset(); // return offset
paginator.getLimit(); // return limit
});
or use with express
var Paginator = require('bookshelf-paginator');
app.get('/people', function(req, res) {
var paginator = new Paginator('Person', {
limit: req.query.limit || 25,
filterBy: ['firstname', 'lastname']
});
paginator.paginate().then(function(paginator) {
paginator.setHeaders(res);
res.json(paginator.getData());
});
});
Filter and sort by related fields
var Paginator = require('bookshelf-paginator');
var paginator = new Paginator('Person', {
limit: 15,
filterBy: ['firstname', 'lastname', 'languages.name']
});
paginator.paginate({'languages.name': 'Spanish', 'sortBy': '-lastname'}).then(function(paginator) {
paginator.getData(); // return a person collection
paginator.getTotal(); // return total register
paginator.getOffset(); // return offset
paginator.getLimit(); // return limit
});
FAQs
Allow paginate your models with ease
We found that bookshelf-paginator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.