Skip to content

feat(postgrest): add range to the typed query - #1318

Open
AndroidPoet wants to merge 1 commit into
supabase:mainfrom
AndroidPoet:feat/postgrest-typed-range
Open

AndroidPoet wants to merge 1 commit into
supabase:mainfrom
AndroidPoet:feat/postgrest-typed-range

Conversation

@AndroidPoet

Copy link
Copy Markdown
Contributor

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 lists range(_:) next to limit(_:) on the typed query, and the string builder already has range(from:to:referencedTable:).

Fix

Add range(_:) to PostgrestTypedQuery, taking a ClosedRange<Int> of zero-based inclusive row indexes and delegating to the existing builder method, so the wire encoding (offset plus limit, with limit = count) is shared with the string builder rather than duplicated. Like limit(_:) it moves the request into the transform phase.

try await client.from(Todo.self)
  .select()
  .where { $0.isDone.eq(false) }
  .order { $0.id.asc() }
  .range(20...29)
  .execute()

sends offset=20&limit=10.

ClosedRange follows 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 prefer range(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-embed order and limit are not on the typed surface yet either, so they can land together.

Tests

Three tests in PostgrestTypedQueryWhereTests:

  • range(10...19) sends offset=10 and limit=10
  • range(0...0) sends offset=0 and limit=1, the single-row edge
  • range chained after where and order keeps both and adds the offset and limit

Full PostgRESTTests and PostgrestMacrosTests suites pass.

Additive public API: PostgrestTypedQuery.range(_:), registered under database.using_modifiers.range in sdk-compliance.yaml. DocC on the new symbol builds without warnings.

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.
@AndroidPoet
AndroidPoet requested review from a team and grdsdev as code owners September 7, 2026 13:57
@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 2a28cddb-cdec-4734-b263-d9197d8a1cf8

📥 Commits

Reviewing files that changed from the base of the PR and between 3204541 and 2533ccd.

📒 Files selected for processing (3)
  • Sources/PostgREST/Query/PostgrestTypedQuery+Where.swift
  • Tests/PostgRESTTests/PostgrestTypedQueryWhereTests.swift
  • sdk-compliance.yaml

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.


📝 Summary

Summary by CodeRabbit

  • New Features

    • Added support for applying inclusive, zero-based row ranges to typed queries.
    • Range queries can be combined with filtering and ordering options.
  • Tests

    • Added coverage for ranges with offsets, single-row ranges, and combined query modifiers.

Walkthrough

Adds PostgrestTypedQuery.range(_:) for inclusive ClosedRange<Int> values. The method forwards the bounds to builder.range(from:to:) and returns a query in PostgrestTransformPhase. Tests verify offset and limit generation, zero-based ranges, and chaining with where and order. The SDK compliance registry now includes PostgrestTypedQuery.range.

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
Loading

Merge Risk: ⚪ Minimal · up to 2533c

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant