Use Claude to Implement Cursor-Based Pagination
Offset pagination (LIMIT 20 OFFSET 1000) is slow on large tables and breaks if rows are inserted or deleted between pages. Cursor-based pagination is the scalable alternative — and Claude can implement it for you.
Implement cursor-based pagination for my /api/posts endpoint.
Use the post ID as the cursor, encoded as base64.
Return a next_cursor field in the response and accept a cursor query param.
Paste in your existing controller and Claude will refactor the query, add the cursor encode/decode logic, and update the response shape. It understands the tradeoffs and can explain them as it writes.
For tie-breaking on timestamp columns, be explicit:
Add cursor pagination to PostController@index.
The cursor should encode both created_at and id to handle posts
created at the same timestamp. Use base64 encoding.
Paginate 15 results per page.
Claude will generate the correct WHERE (created_at, id) < (?, ?) clause and handle both ascending and descending sort orders. For Laravel users, it can use the built-in cursorPaginate() method or build a raw implementation depending on your constraints.
Cursor pagination scales to millions of rows — ask Claude to implement it once and move on.
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.