feat(postgrest): add range to the typed query - #1318
AndroidPoet wants to merge 1 commit into
Conversation
The typed query could limit but not offset, so a paginated view had no way to fetch page two without dropping to the string builder. Add range(_:) taking a closed range of zero-based row indexes, delegating to the existing builder so the wire encoding stays shared.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review. 📝 SummarySummary by CodeRabbit
WalkthroughAdds Sequence Diagram(s)sequenceDiagram
participant SelectQueryTest
participant PostgrestTypedQuery
participant PostgrestRequestBuilder
SelectQueryTest->>PostgrestTypedQuery: range(10...19)
PostgrestTypedQuery->>PostgrestRequestBuilder: range(from: 10, to: 19)
PostgrestRequestBuilder-->>SelectQueryTest: offset=10 and limit=10
Merge Risk: ⚪ Minimal · up to Typed PostgREST queries now support inclusive zero-based pagination ranges, producing the expected offset and limit parameters while preserving filtering and ordering composition. No current merge-blocking risk remains. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
The typed query has
limit(_:)but no way to set an offset, so it cannot fetch anything past the first page.execute(count:)is documented as what a paginated view needs, yet page two is unreachable without dropping to the string builder. The v3 design listsrange(_:)next tolimit(_:)on the typed query, and the string builder already hasrange(from:to:referencedTable:).Fix
Add
range(_:)toPostgrestTypedQuery, taking aClosedRange<Int>of zero-based inclusive row indexes and delegating to the existing builder method, so the wire encoding (offsetpluslimit, withlimit = count) is shared with the string builder rather than duplicated. Likelimit(_:)it moves the request into the transform phase.sends
offset=20&limit=10.ClosedRangefollows the spec's single-argument spelling and rules out an empty or inverted range at the type level, which the two-integer form cannot. If you would preferrange(from:to:)for symmetry with the string builder, that is a one-line change and I am happy to switch. Embedded-relation pagination (referencedTable) is left out on purpose; per-embedorderandlimitare not on the typed surface yet either, so they can land together.Tests
Three tests in
PostgrestTypedQueryWhereTests:range(10...19)sendsoffset=10andlimit=10range(0...0)sendsoffset=0andlimit=1, the single-row edgerangechained afterwhereandorderkeeps both and adds the offset and limitFull
PostgRESTTestsandPostgrestMacrosTestssuites pass.Additive public API:
PostgrestTypedQuery.range(_:), registered underdatabase.using_modifiers.rangeinsdk-compliance.yaml. DocC on the new symbol builds without warnings.