Skip to main content
The createTPaginatedQuery function creates a sub-router with three separate procedures for paginated tables: getItems, getCount, and getDescription. Each procedure has its own typed input and output.

Basic Usage

Pagination Parameters

The getItems function receives pagination parameters as its first argument, ready to use with MongoDB:
Example:

Procedures

Each createTPaginatedQuery returns three separate tRPC procedures, accessible as nested routes:

getItems

Returns the paginated items. Input includes pagination fields and custom params.

getCount

Returns the total count (for calculating total pages on the client). Input includes only custom params.

getDescription

Returns the sorting configuration. Takes no input.

Options

Pagination Fields

The following fields are available in the getItems input:

Type Inference

Item types are automatically inferred from the getItems return type - no manual type annotations needed:
For proper type inference with InferRouterOutputs, use the custom InferRouterOutputs type from @orion-js/trpc:

Schema Cleaning

If you provide a returns schema, items will be cleaned/filtered according to that schema:

Client Usage Example