Skip to content

feat(postgrest)!: type a partial select as a partial row instead of the full row - #1897

Merged
spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-1976-partial-select-selection-type
Sep 30, 2026
Merged

spydon merged 2 commits into
mainfrom
lukasklingsbo/sdk-1976-partial-select-selection-type

Conversation

@spydon

@spydon spydon commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes SDK-1976.

Problem

select([Books.id, Books.title]) on the typed builders resolved to List<BooksRow>. The generated row type reads _json['created_at'] as String, so every getter of a column the list left out compiled and crashed at runtime with a null cast that did not name the column. Since #1891 the same applied to embeds: Books.author.select([Authors.name]) was read through BooksRow.authors, which converted the partial embedded object into a full AuthorsRow.

What changes

postgrest

  • selectOnly([...]) replaces select([...]) on PostgrestTypedQueryBuilder and PostgrestTypedTransformBuilder and resolves to List<PostgrestPartialRow<Row>>. select() keeps resolving to List<Row>.

  • PostgrestPartialRow.read reads a value through the select list entry, so the entry types the read and an entry of another table does not compile:

    final books = await client
        .table(Books.table)
        .selectOnly([Books.id, Books.title, Books.author.select([Authors.name])]);
    
    final int id = books.first.read(Books.id);
    final String? author = books.first.read(Books.author)?.read(Authors.name);
    books.first.read(Books.createdAt); // StateError: `created_at` was not selected. The row holds `id`, `title`, `authors`.

    A PostgrestColumn reads as its value type, a PostgrestNullableColumn, a derived expression and a JSON path as the nullable form, a to-one relation as a nested PostgrestPartialRow?, a to-many relation as a list of them. Aggregates come back under the function name, a cast under the key of what was cast, a JSON path under its last key. Entries of one relation merge into the nested row the way they merge into one embed, and Books.author.select() lets any column of the embedded table be read. A selected nullable column that stripNulls() dropped reads null; an unselected one throws.

  • PostgrestStoredColumn is the new sealed base of PostgrestColumn and PostgrestNullableColumn, which no longer extend each other, since one reads as Value and the other as Value?. primaryKey, relations key columns, onConflict, and the stream primaryKey and order take it.

  • fromJson on the column tokens and on PostgrestCastTarget decodes a value the way the generated row getters do, so read produces DateTime, enums, Uint8List, ranges and so on. sum and avg read as double even when PostgREST sends an integer; min and max inherit the decoder of the column.

  • single() and maybeSingle() move to the PostgrestTypedRowsBuilder extension on PostgrestTypedTransformBuilder<Row, List<Element>>, so they keep the element type of select() and selectOnly() alike, and a mutation without a trailing select no longer offers a single() that could only fail.

  • responseKey on every PostgrestSelectable and on relations names the key the entry comes back under.

supabase_typegen

  • Emits one private decoder per Dart type that differs from its JSON form, DateTime _dateTimeFromJson(Object json) => DateTime.parse(json as String);, and passes it to the column tokens: PostgrestColumn<BooksRow, DateTime>('created_at', fromJson: _dateTimeFromJson).
  • Drops the relation getters from the row types. select() sends *, which never includes an embed, so they could only be reached through a partial select, which now reads relations through read.

Elsewhere

  • supabase: the typed stream builder takes PostgrestStoredColumn.
  • sdk-compliance.yaml: registers the new symbols and moves the ones that changed owner.

Breaking changes

All on the @experimental typed surface:

  • select([columns]) is selectOnly(columns) and resolves to partial rows.
  • PostgrestNullableColumn is not a PostgrestColumn; lists of key columns take PostgrestStoredColumn.
  • single() and maybeSingle() only exist on list-shaped builders.
  • Generated row types have no relation getters.

Tests

  • New postgrest/test/postgrest_partial_row_test.dart covers typed reads, decoders, nullable and stripped columns, aggregates, casts, JSON paths, to-one and to-many relations, merged embed entries, the * rules, embedded entry reads, single, maybeSingle, count, and a trailing selectOnly on a mutation.
  • Typegen generator tests cover the decoder emission and naming, including the List<String$> enum array next to List<String>, and that row types carry no relation getters. The behavior tests read embeds through the relation.
  • Full postgrest suite against the local stack, supabase and supabase_typegen suites, DCM and the compliance symbol, drift and schema checks all pass locally.

Summary by CodeRabbit

  • New Features
    • Added typed partial-row results for selecting specific columns and reading derived values, JSON paths, and embedded relations.
    • Added selectOnly for explicit column selection; select() now returns full typed rows.
    • Added single() and maybeSingle() for typed query results.
    • Added automatic decoding for supported column types, including vectors and custom converters.
  • Documentation
    • Updated guidance and examples for partial selections and reading embedded rows.

…he full row

`select([Books.id, Books.title])` on the typed builders resolved to
`List<Row>`, so the getters of every column left out compiled and failed
at runtime with a null cast that did not name the column. The same held
for embeds, whose row getters converted a partial embedded object into a
full row of the target.

The column list moves to `selectOnly`, which resolves to
`PostgrestPartialRow`s. Values are read through the select list entries,
`row.read(Books.title)`, so the entry types the read and an entry the
list did not ask for throws a `StateError` naming it. Relations are read
the same way, `row.read(Books.author)?.read(Authors.name)`, and so are
aggregates, casts and JSON paths under the key PostgREST answers with.
`select()` keeps resolving to the full `Row`.

To type the reads, `PostgrestNullableColumn` no longer extends
`PostgrestColumn`; both extend the new `PostgrestStoredColumn`, which
every list of key columns now takes. Column tokens carry a `fromJson`
decoder so a partial row produces the same Dart values as the row
getters, and `single()` and `maybeSingle()` move to an extension on the
list-shaped builders, so a mutation without a trailing select has none.

`supabase_typegen` emits the decoders as one private function per Dart
type, passes them to the column tokens, and drops the relation getters
from the row types, which only a partial select could have populated.
@spydon
spydon requested a review from a team as a code owner September 29, 2026 13:08
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository: supabase/supabase-flutter/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 6586b6a0-ab14-4aa3-a179-a4d285f7f026

📥 Commits

Reviewing files that changed from the base of the PR and between 9c428b9 and 0a1a395.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: supabase/supabase-flutter/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 5f5f490d-52c0-43ee-a9a0-cf530b8bac2e

📥 Commits

Reviewing files that changed from the base of the PR and between e1f4a83 and 9c428b9.

📒 Files selected for processing (24)
  • packages/postgrest/lib/src/postgrest_column_expression.dart
  • packages/postgrest/lib/src/postgrest_derived_expression.dart
  • packages/postgrest/lib/src/postgrest_embedded_relation.dart
  • packages/postgrest/lib/src/postgrest_partial_row.dart
  • packages/postgrest/lib/src/postgrest_table.dart
  • packages/postgrest/lib/src/postgrest_table_request.dart
  • packages/postgrest/lib/src/postgrest_typed_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_query_builder.dart
  • packages/postgrest/lib/src/postgrest_typed_transform_builder.dart
  • packages/postgrest/lib/src/postgrest_vector.dart
  • packages/postgrest/test/postgrest_column_expression_test.dart
  • packages/postgrest/test/postgrest_partial_row_test.dart
  • packages/postgrest/test/resource_embedding_test.dart
  • packages/postgrest/test/table_executor_test.dart
  • packages/postgrest/test/typed_query_test.dart
  • packages/supabase/lib/src/supabase_typed_query_builder.dart
  • packages/supabase/lib/src/supabase_typed_stream_builder.dart
  • packages/supabase_typegen/README.md
  • packages/supabase_typegen/lib/src/dart_generator.dart
  • packages/supabase_typegen/test/dart_generator_test.dart
  • packages/supabase_typegen/test/generated_schema_behavior_test.dart
  • packages/supabase_typegen/test/goldens/hostile_schema.dart
  • packages/supabase_typegen/test/goldens/supabase_schema.dart
  • sdk-compliance.yaml

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Typed queries now distinguish full-row select() results from partial-row selectOnly() results. Partial rows read selected columns, derived values, and embedded relations through typed tokens. Generated schema code supplies JSON decoders for converted types and no longer emits relation-reading row getters.

Changes

Typed partial-row selections

Layer / File(s) Summary
Readable values and partial-row decoding
packages/postgrest/lib/src/postgrest_column_expression.dart, packages/postgrest/lib/src/postgrest_derived_expression.dart, packages/postgrest/lib/src/postgrest_partial_row.dart
Selectable entries expose response keys and typed decoding. PostgrestPartialRow reads selected values and reports when an entry was not selected.
Partial selection and embedded-row reads
packages/postgrest/lib/src/postgrest_typed_query_builder.dart, packages/postgrest/lib/src/postgrest_typed_transform_builder.dart, packages/postgrest/lib/src/postgrest_typed_builder.dart, packages/postgrest/lib/src/postgrest_embedded_relation.dart, packages/postgrest/test/*
select() returns full rows, while selectOnly() returns partial rows. Relation reads decode nested partial rows. Tests cover selected values, embedded selections, and query result shapes.
Generated column decoders and relation access
packages/supabase_typegen/lib/src/dart_generator.dart, packages/supabase_typegen/test/*, packages/supabase_typegen/README.md
The generator emits JSON decoders for converted column types and no longer emits relation-reading row getters. Generated-schema tests and examples use selectOnly and read.
Stored-column API integrations
packages/postgrest/lib/src/postgrest_table.dart, packages/postgrest/lib/src/postgrest_table_request.dart, packages/postgrest/lib/src/postgrest_vector.dart, packages/supabase/lib/src/supabase_typed_*.dart, sdk-compliance.yaml
Primary keys, conflict columns, stream ordering, and stream filters use stored-column types. Vector columns provide JSON decoders. The SDK capability registry lists the typed-read APIs.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant TypedQuery as PostgrestTypedQueryBuilder
  participant Transform as PostgrestTypedTransformBuilder
  participant PartialRow as PostgrestPartialRow
  participant Relation as PostgrestToOneRelation
  TypedQuery->>Transform: selectOnly(selections)
  Transform->>PartialRow: wrap result row with selections
  PartialRow->>Relation: read(relation)
  Relation->>PartialRow: decode nested partial row
Loading

Suggested reviewers: grdsdev

Merge Risk: ⚪ Minimal · up to 9c428

No merge-blocking issue was identified in the typed partial-row changes; the reviewed single-row and array-read paths preserve their expected behavior.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 9c428

Partial selections now produce a distinct result type across several client packages. The reviewed paths retain the existing request execution route and narrow, rather than expand, typed stream column inputs. The public contract change still requires coordinated adoption, and server-side authorization was not assessed.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed typed APIs can affect many client dependents, but the reviewed selection path does not introduce a separate endpoint, credential, or request executor. Database authorization remains outside the inspected scope.

Trust Boundaries and Controls

  • observed — Caller-supplied selections shape the existing PostgREST select request; response values are read through selected keys and column decoders. These client checks do not establish what the server permits a caller to retrieve.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main breaking change: partial selections now return partial rows instead of full rows.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

@spydon
spydon enabled auto-merge (squash) September 30, 2026 09:27
@spydon
spydon merged commit 9378ac8 into main Sep 30, 2026
40 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-1976-partial-select-selection-type branch September 30, 2026 09:33
spydon added a commit that referenced this pull request Oct 9, 2026
…xecutor (#1939)

## What

#1857 was merged before the plugin seam was ready. This takes the plugin
system and the executor extension point back out of the public API.
#1940 brings them back for review.

The typed builders keep their internal structure: they still collect a
`PostgrestTableRequest` and run it through `PostgrestHttpTableExecutor`.
Several later PRs build on that (#1907, #1913, #1910, #1897 and others).
Only the public surface is removed:

- `SupabaseClientPlugin`, `SupabaseClient(plugins:)`,
`SupabaseClient.plugins`, `Supabase.initialize(plugins:)` and the plugin
resume handling in the Flutter lifecycle listener, and
`testSupabaseClient(plugins:)`.
- `PostgrestClient.table(executor:)`,
`SupabaseQuerySchema(tableExecutor:)` and
`PostgrestTypedBuilder.request`.
- `PostgrestTableExecutor`, `PostgrestHttpTableExecutor`,
`PostgrestTableRequest`, `PostgrestTableResult`,
`PostgrestTableOperation`, `PostgrestResultShape`,
`PostgrestEmbeddedPage`, `PostgrestExplainOptions` and
`PostgrestRequestOptions` are no longer exported.
- `PostgrestTypedQueryBuilder` and `SupabaseTypedQueryBuilder` take a
`client` instead of an `executor`.

The matching `sdk-compliance.yaml` entries and the plugin paragraph in
`MIGRATION.md` are removed, and `AGENTS.md` describes the executor as
internal.

## Tests

`table_executor_test.dart`, `client_plugin_test.dart` and the Flutter
`plugin_test.dart` are removed with the API they cover. They come back
in #1940. The update/delete test in `typed_query_test.dart` used to
assert on `request.filter`. It now checks the filter on the request that
goes out.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Breaking Changes**
* Supabase client initialization no longer accepts plugins, and plugin
lifecycle and request-wrapping support have been removed.
* Typed table queries no longer allow supplying a custom executor.
Supporting typed-query types and request details are no longer exposed
through the main library exports.
* **Documentation**
* Updated query-building and migration guidance to reflect the current
typed table query behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

2 participants