0.0.2 • Published 6 years ago

bookshelf-simplepaginate v0.0.2

Weekly downloads
136
License
MIT
Repository
github
Last release
6 years ago

bookshelf-simplepaginate

This Bookshelf.js plugin provides a Laravel like simple pagination to your models.

Installation

Install the package via npm:

$ npm install --save bookshelf-simplepaginate

Usage

var bookshelf = require('bookshelf')(knex);

bookshelf.plugin(require('bookshelf-simplepaginate'));
Car.query(function (qb) {
    qb.innerJoin('manufacturers', 'cars.manufacturer_id', 'manufacturers.id');
    qb.groupBy('cars.id');
    qb.where('manufacturers.country', '=', 'Sweden');
}).simplePaginate({
    limit: 15, // Defaults to 10 if not specified
    page: 3, // Defaults to 1 if not specified
    withRelated: ['engine'] // Passed to Model#fetchAll
}).then(function (results) {
    console.log(results); 
});

Output of results:

{
   "data": [],
   "meta": {
      "pagination": {
         "count": 53,
         "per_page": 15,
         "current_page": 1,
         "links": {
            "previous": null,
            "next": 1
         }
      }
   }
}