Skip to content

Instantly share code, notes, and snippets.

View DomenicoColandrea86's full-sized avatar

Domenico Colandrea DomenicoColandrea86

View GitHub Profile
@DomenicoColandrea86
DomenicoColandrea86 / knex-pagination.js
Created July 3, 2018 18:53 — forked from andremsantos/knex-pagination.js
Adding pagination to knex.js
module.exports = function(dbConfig) {
var knex = require('knex')(dbConfig);
var KnexQueryBuilder = require('knex/lib/query/builder');
KnexQueryBuilder.prototype.paginate = function (per_page, current_page) {
var pagination = {};
var per_page = per_page || 10;
var page = current_page || 1;
if (page < 1) page = 1;