Skip to content

A simple bookshelfjs pagination based on Laravels simplePaginate.

License

Notifications You must be signed in to change notification settings

Askedio/bookshelf-simplepaginate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: 100, // 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_total": 1000,
         "page_total": 10,
         "count_per_page": 100,
         "per_page": 100,
         "current_page": 1,
         "links": {
            "previous": null,
            "next": 1
         }
      }
   }
}

About

A simple bookshelfjs pagination based on Laravels simplePaginate.

Resources

License

Stars

Watchers

Forks

Packages

No packages published