bookshelf-simplepaginate

0.0.2 • Public • Published

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
         }
      }
   }
}

Package Sidebar

Install

npm i bookshelf-simplepaginate

Weekly Downloads

139

Version

0.0.2

License

MIT

Unpacked Size

8.28 kB

Total Files

5

Last publish

Collaborators

  • askedio