
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
typeorm-cursor-paginate
Advanced tools
Cursor-based pagination that works with TypeORM Query Builder. Read about the general idea of cursor-based pagination here.
This package is a fork of the typeorm-paginator package with some tweaks. See the Key differences from typeorm-paginator section for more details.
The biggest difference is directional cursors. Directional cursors store the direction of pagination inside them. They allow to provide only one parameter to paginate in any direction.
npm install typeorm-cursor-paginate --save
Start by importing the CursorPaginator class:
import { CursorPaginator } from "typeorm-cursor-paginate";
Instantiate the paginator with your target entity and define the ordering strategy. In this example, users are sorted by their name in ascending order and by id in descending order:
const paginator = new CursorPaginator(User, {
orderBy: [{ name: "ASC" }, { id: "DESC" }],
});
Prepare your query:
const query = repoUsers.createQueryBuilder();
// you can apply desired "where" conditions to the query
Use the paginator to fetch the initial set of results. Here, a limit of 2 items per page is specified:
const firstPageResult = await paginator.paginate(query, { limit: 2 });
Output structure:
{
nodes: [
User { id: 4, name: 'a' },
User { id: 3, name: 'b' },
],
hasPrevPage: false,
hasNextPage: true,
prevPageCursor: "some-cursor-string",
nextPageCursor: "some-cursor-string",
}
To retrieve the next set of results, pass the nextPageCursor from the first query:
const secondPageResult = await paginator.paginate(query, {
limit: 2,
// Use the nextPageCursor from the previous result
pageCursor: firstPageResult.nextPageCursor,
});
Output structure:
{
nodes: [
User { id: 1, name: 'c' },
User { id: 2, name: 'c' },
],
hasPrevPage: true,
hasNextPage: true,
prevPageCursor: "some-cursor-string",
nextPageCursor: "some-cursor-string",
}
typeorm-paginatortypeorm-paginator is the original package that this one is based on.
Here are the key differences:
orderBy property only accepts keys that are present in the entity.PageCursor class was removed. This package is about cursor-based pagination.typeorm-cursor-paginationtypeorm-cursor-pagination is another package that provides cursor-based pagination for TypeORM. As of now, March 2025, it gets more and more popular than the typeorm-paginator package.
Here are the key differences:
orderBy array had to have the same direction. This package allows to provide different directions for different columns.typeorm-paginator).All contributions are welcome, open a pull request or issue any time.
Please try to commit your changes using a descriptive commit message.
Released under the MIT License
FAQs
Cursor-based pagination with directional cursors.
We found that typeorm-cursor-paginate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.