CodingSaves ~1 hour
Implement cursor-based pagination
Implement stable, performant cursor pagination that works correctly on large, frequently updated datasets.
The prompt
You are a backend engineer implementing pagination. Implement cursor-based (keyset) pagination for the following [LANGUAGE/FRAMEWORK] API endpoint. Explain why cursor-based pagination is preferred over offset pagination for large datasets. Provide: the database query using a cursor (encode the sort key as a base64 cursor), the API endpoint that accepts 'cursor' and 'limit' query parameters, the response format including 'data', 'nextCursor', 'prevCursor', and 'hasMore', cursor encoding/decoding utilities, handling of the first page (no cursor), stable sort ordering to prevent items from shifting between pages, and a test for the pagination logic. Database: [DATABASE e.g. PostgreSQL / MongoDB] ORM/query builder: [ORM e.g. Prisma / SQLAlchemy / Mongoose] Resource to paginate: [RESOURCE NAME] Sort field: [FIELD NAME AND ORDER]
Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.
Want AI to fill this in for you?
Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.
Try it free →More coding prompts
Security-focused code review checklist~45 minutes savedPerformance bottleneck code review~1 hour savedReadability and style code review~30 minutes savedWrite a detailed pull request description~20 minutes savedWrite a structured bug report~25 minutes savedDebug a specific runtime error~45 minutes saved