The `nestjs-typeorm-paginate` library provides a robust and strictly typed pagination solution for NestJS applications integrated with TypeORM. It simplifies the process of generating pagination objects from TypeORM repositories or query builders, ensuring type safety throughout your codebase. The current stable version is 4.1.0, which is specifically designed for compatibility with TypeORM `^0.3.0` and a broad spectrum of `@nestjs/common` versions up to `^11.0.0`. The project's release cadence is often tied to major version updates of TypeORM and NestJS, necessitating careful version management during upgrades. Its key differentiators include explicit support for both `Repository` instances and `QueryBuilder` objects, offering flexibility in how data is queried, alongside comprehensive TypeScript typings for all pagination options and the resulting paginated data structure, making it a reliable choice for complex data presentation needs.
npm install nestjs-typeorm-paginateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to implement pagination in a NestJS application using `nestjs-typeorm-paginate`. It covers the setup of a `CatEntity`, a `CatService` that utilizes the `paginate` function with a TypeORM `QueryBuilder`, and a `CatsController` that handles URL query parameters for page and limit, returning a `Pagination` object.
Upgrade your TypeORM dependency to `^0.3.0` or later. If maintaining TypeORM `^0.2.6`, you must use `nestjs-typeorm-paginate^3.2.0`.
Always provide the `route` property in your `IPaginationOptions` object, specifying the base URL for your paginated API endpoint (e.g., `{ page, limit, route: 'http://api.example.com/items' }`).Consult the package's `CHANGELOG.md` or TypeScript type definitions (`.d.ts` files) when upgrading to understand any structural changes to the pagination objects or options.
Verify that your TypeORM version (`^0.3.0` or higher) is compatible with `nestjs-typeorm-paginate@4.x`. For TypeORM `^0.2.x`, you should use `nestjs-typeorm-paginate@3.x`.
Ensure you are passing a `route` property within your `IPaginationOptions` object. For example: `this.catService.paginate({ page, limit, route: '/api/cats' })`.Ensure that `TypeOrmModule.forFeature([CatEntity])` is imported in the `imports` array of the relevant NestJS module (e.g., `CatModule`) that provides `CatService`.