Skip to content

fix: paginate drops id from selective queries, orderBy mishandles system fields#41

Merged
pdlug merged 1 commit into
mainfrom
fix/paginate-drops-id
Mar 10, 2026
Merged

fix: paginate drops id from selective queries, orderBy mishandles system fields#41
pdlug merged 1 commit into
mainfrom
fix/paginate-drops-id

Conversation

@pdlug
Copy link
Copy Markdown
Contributor

@pdlug pdlug commented Mar 10, 2026

  • Fix silent data loss in .paginate() + .select(): FieldAccessTracker.record() no longer allows a system field (id, kind) to be downgraded to a props field when
    #recordOrderByFieldsForPagination re-records it, which caused the SQL projection to extract from props->>'id' (nonexistent) instead of the id column.
  • Fix orderBy() for system fields: orderBy("alias", "id") now emits ORDER BY cte.alias_id instead of ORDER BY json_extract(cte.alias_props, '$.id'). Also updated
    #buildCursorContextFromSelectiveRow to handle system field order specs for cursor construction.
  • Add gt/gte/lt/lte to StringFieldAccessor: Enables keyset cursor pagination via whereNode("a", (a) => a.id.lt(cursor)).

Fixes #40

…tem fields

Three related bugs in the query builder:

1. FieldAccessTracker.record() allowed orderBy to overwrite a system field
   (id, kind) as a props field, causing compileSelectiveProjection to emit
   props->>'id' instead of the id column. This made paginate+select return
   undefined for explicitly selected system fields.

2. orderBy() unconditionally wrapped every field as a props JSON path,
   so ordering by system fields like id silently ordered by a nonexistent
   JSON key instead of the actual column.

3. StringFieldAccessor lacked gt/gte/lt/lte operators, preventing keyset
   cursor pagination via whereNode("a", (a) => a.id.lt(cursor)).

  Fixes #40
@pdlug pdlug force-pushed the fix/paginate-drops-id branch from 0ee1b31 to cdc9942 Compare March 10, 2026 05:03
@pdlug pdlug merged commit 68d5432 into main Mar 10, 2026
10 checks passed
@pdlug pdlug deleted the fix/paginate-drops-id branch March 10, 2026 05:06
@github-actions github-actions Bot mentioned this pull request Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: .paginate() drops id system field from selective query results

1 participant