• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An extension of Knex's query builder with `paginate` method that will help with your pagination tasks.

Knex-paginate

npm CI

Extension of Knex's query builder with paginate method that will help with your pagination tasks.

How to set up

To use this lib, first you will have to install it:

npm i knex-paginate --save
// or
yarn add knex-paginate

Then, add the following lines to your Knex set up:

const knex = require('knex')(config);

const { attachPaginate } = require('knex-paginate');
attachPaginate();

Function definition

.paginate(params: IPaginateParams): Knex.QueryBuilder<any, IWithPagination<TResult>>;

interface IPaginateParams {
  perPage: number,
  currentPage: number,
  isFromStart?: boolean,
  isLengthAware?: boolean,
}

interface IWithPagination<T = any> {
  data: T;
  pagination: IPagination;
}

interface IPagination {
  total?: number;
  lastPage?: number;
  currentPage: number;
  perPage: number;
  from: number;
  to: number;
}

How to use

Example

const result = await knex('persons')
   .paginate({ perPage: 10, currentPage: 2 });
// result.data - will hold persons data
// result.pagination - will hold pagination object

pagination object

Key Value
perPage Items per page.
currentPage Current page number.
from Counting ID of the first item of the current page.
to Counting ID of the last item of the current page.

Returned if isLengthAware == true or currentPage == 1 or isFromStart == true:

Key Value
total Total items that the full query contains.
lastPage Last page number.

This lib got inspiration from knex-paginator.

More Repositories

1

bull-board

๐ŸŽฏ Queue background jobs inspector
TypeScript
2,309
star
2

turborepo-gh-artifacts

A TurboRepo local cache server which uploads artifact cache to GH artifacts.
TypeScript
123
star
3

i18next-hmr

I18Next HMR๐Ÿ”ฅ webpack / vite plugin that allows reload translation resources instantly on the client & the server.
JavaScript
107
star
4

knex-mock-client

A mock client for knex which allows you to write unit tests with DB interactions
TypeScript
53
star
5

knex-on-duplicate-update

A Knex plugin that adds .onDuplicateUpdate() function to knex's query builder.
JavaScript
28
star
6

i18next-locales-sync

Syncs i18next locale resource files against a primary language.
TypeScript
24
star
7

turborepo-gh-artifacts-example

Turborepo with Github action cache
JavaScript
8
star
8

postcss-extract-styles

PostCSS plugin that extracts styles from css based on decelerations matching.
JavaScript
4
star
9

postcss-decrease-specificity

PostCSS plugin that decreases the specificity of given selector
JavaScript
3
star
10

rspack-express-js

Express.js app bundled with Rspack with HMR
TypeScript
2
star
11

kodi-addon-release

Bump KODI addon version, create tag, update changelog, commit and release the addon in one step.
JavaScript
2
star
12

cibus-chrome-extension

A Chrome Extension to help you monitor your Cibus expenses.
TypeScript
2
star
13

babel-plugin-transform-react-remove-display-name

Make React component `displayName` property available only in none production environment during the build โœจ
TypeScript
1
star
14

electric-pulse

A pi pico electric pulse meter
Python
1
star
15

tpa-style-scss

Set of SCSS functions that help you to build TPA style custom syntax.
SCSS
1
star