implementing-query-pagination

Implement cursor-based or offset-based pagination for Prisma queries.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/djankies/claude-configs --skill implementing-query-pagination
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: implementing-query-pagination
Source: https://github.com/djankies/claude-configs/tree/main/prisma-6/skills/implementing-query-pagination
Command: npx skills add https://github.com/djankies/claude-configs --skill implementing-query-pagination

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Efficient pagination is essential for large datasets. This Skill teaches correct Prisma 6 pagination patterns, including cursor-based and offset-based approaches and the trade-offs.

Core Features & Use Cases

  • Cursor pagination: stable performance regardless of dataset size; ideal for infinite scroll.
  • Offset pagination: simple but degrades with large data; best for small, static datasets.
  • Indexing and ordering considerations to support pagination efficiently.

Quick Start

Start with cursor pagination by default, using take, cursor, and orderBy; reserve offset pagination for small admin tables or internal tooling when page jumps are required.

Frequently Asked Questions about implementing-query-pagination

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement pagination in Prisma for large datasets?

Pagination in Prisma uses cursor-based or offset-based strategies. Cursor pagination provides stable performance regardless of dataset size by tracking a unique field position; offset pagination uses skip/take but degrades with large data. Choose cursor pagination for infinite scroll and offset for small, static datasets.

What's the difference between cursor and offset pagination in Prisma?

Cursor pagination marks a position using a unique field and orders results consistently, ideal for infinite scroll with reliable performance. Offset pagination skips N rows and fetches the next batch, simpler to implement but slower on large datasets since it rescans skipped rows.

How do I set up cursor pagination with Prisma's take and orderBy?

Cursor pagination uses take to limit results, orderBy to establish consistent ordering, and cursor to specify the starting position. Include the cursor field in orderBy, pass the previous record's cursor value to resume pagination, and return nextCursor from results for the next page.

When should I use offset pagination instead of cursor pagination?

Offset pagination suits small, static datasets in admin dashboards or internal tooling where page jumps are required and performance is less critical. Cursor pagination is preferred by default for production APIs and infinite-scroll interfaces serving large datasets efficiently.

How do I handle composite cursors for non-unique fields in Prisma?

Composite cursors combine multiple fields to create a unique sort position when individual fields aren't unique. Include all ordering fields in the cursor definition and orderBy clause to ensure stable, reproducible pagination across requests without duplicate or skipped records.

What indexing should I add to support efficient pagination?

Create database indexes on fields used in orderBy clauses to accelerate cursor lookups and range scans. For composite cursors, use compound indexes matching the orderBy field order; proper indexing prevents full table scans and ensures pagination remains fast as datasets grow.