Skip to content

diegosucaria/node-orm-paging

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ORM Pagination Helper Plugin

This plugin adds a pagination helper function for ORM.

This fork only returns promises. No callback support. Only ES6+

Dependencies

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

Install

npm install orm-paging

DBMS Support

Any driver supported by ORM is supported by this plugin.

Usage

Model.pages([conditions, ])   // total pages
Model.page([conditions, ],page)  // get page

Example

var orm = require("orm");
var paging = require("orm-paging");

orm.connect("mysql://username:password@host/database", async function (err, db) {
	if (err) throw err;

	db.use(paging);

	let Person = db.define("person", {
		name      : String,
		surname   : String,
		age       : Number
	});
	Person.settings.set("pagination.perpage", 10); // default is 20

	let pages = await Person.pages();
	console.log("Total pages: %d", pages);
    
    let people = await Person.page(3);
	
    let pagesWithCondition = await Person.pages({age: orm.gt(3)});
	console.log("Total pages: %d", pagesWithCondition);
	let people = await Person.page({age: orm.gt(3)},3);
	
});

About

NodeJS ORM Pagination Helper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%