orm-paging

ORM Pagination Helper

ORM Pagination Helper Plugin

This plugin adds a pagination helper function for ORM.

Of course you need orm to use it. Other than that, no more dependencies.

npm install orm-paging

Any driver supported by ORM is supported by this plugin.

Model.pages(cb)   // total pages 
Model.page(page) // get page 
var orm = require("orm");
var paging = require("orm-paging");
 
orm.connect("mysql://username:password@host/database", function (errdb) {
    if (err) throw err;
 
    db.use(paging);
 
    var Person = db.define("person", {
        name      : String,
        surname   : String,
        age       : Number
    });
    Person.settings.set("pagination.perpage", 10); // default is 20 
 
    Person.pages(function (errpages) {
        console.log("Total pages: %d", pages);
 
        Person.page(3).order("name").run(function (errpeople) {
            // should get you page 3, which means people from index 20 to 29 (ordered by name) 
        });
    });
});