77
88Cursor-based pagination works with [ TypeORM Query Builder] ( https://typeorm.io/#/select-query-builder ) .
99
10+ [ Why or What is Cursor-Based Pagination] ( https://jsonapi.org/profiles/ethanresnick/cursor-pagination/ )
11+
12+ > If this project is helpful for you to save your time reinventing the wheel, I truly appreciate you all for your stars ⭐⭐⭐ and contributions 💪💪💪.
13+
1014## Installation
1115
1216` npm install typeorm-cursor-pagination --save `
1317
1418## Usage
1519
16- Query first page without any cursor
20+ ### Query first page without any cursor
1721
1822``` typescript
1923import { getConnection } from " typeorm" ;
@@ -36,7 +40,7 @@ const paginator = buildPaginator({
3640const { data, cursor } = await paginator .paginate (queryBuilder );
3741```
3842
39- The ` buildPaginator ` function has the following options:
43+ ** The ` buildPaginator ` function has the following options**
4044
4145* ` entity ` [ required] : TypeORM entity.
4246* ` alias ` [ optional] : alias of the query builder.
@@ -47,7 +51,7 @@ The `buildPaginator` function has the following options:
4751 * ` beforeCursor ` : the before cursor.
4852 * ` afterCursor ` : the after cursor.
4953
50- ` paginator.paginate(queryBuilder) ` returns the entities and cursor for next iteration
54+ ** ` paginator.paginate(queryBuilder) ` returns the entities and cursor for the next iteration**
5155
5256``` typescript
5357interface PagingResult <Entity > {
@@ -61,7 +65,7 @@ interface Cursor {
6165}
6266```
6367
64- Query next page by ` afterCursor `
68+ ### Query next page by ` afterCursor `
6569
6670``` typescript
6771const nextPaginator = buildPaginator ({
@@ -72,9 +76,11 @@ const nextPaginator = buildPaginator({
7276 afterCursor: cursor .afterCursor ,
7377 },
7478});
79+
80+ const { data, cursor } = await nextPaginator .paginate (queryBuilder );
7581```
7682
77- Query prev page by ` beforeCursor `
83+ ### Query prev page by ` beforeCursor `
7884
7985``` typescript
8086const prevPaginator = buildPaginator ({
@@ -85,6 +91,8 @@ const prevPaginator = buildPaginator({
8591 beforeCursor: cursor .beforeCursor ,
8692 },
8793});
94+
95+ const { data, cursor } = await prevPaginator .paginate (queryBuilder );
8896```
8997
9098## Integration Test with Docker
0 commit comments