feat(db): support multi-source from queries#1537
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Add union-style from handling across the query builder, compiler, optimizer, live traversal, and tests so independent sources can feed one live collection. Co-authored-by: Cursor <cursoragent@cursor.com>
Tighten union join typing, avoid inactive guarded include evaluation, and document multi-source ordering defaults. Co-authored-by: Cursor <cursoragent@cursor.com>
Add runtime and type coverage for union branches that are joined and projected subqueries, since that is the main pre-filtering pattern. Co-authored-by: Cursor <cursoragent@cursor.com>
Resolve multi-source subquery join targets per branch so safe coalesce projections can load indexed subsets while computed or limited branches deopt to eager loading. Co-authored-by: Cursor <cursoragent@cursor.com>
Share union-aware lazy target resolution between joins and includes so correlated child collections can be built from subquery or multi-source sources without crashing. Co-authored-by: Cursor <cursoragent@cursor.com>
Carry nested include routing through QueryRef sources and preserve keyed incremental updates so child live queries receive streaming materialization changes. Co-authored-by: Cursor <cursoragent@cursor.com>
Tighten branch key encoding, join pushdown nullability, lazy target resolution, and conditional/grouped projection semantics based on review feedback. Co-authored-by: Cursor <cursoragent@cursor.com>
Restore nested update cloning after rebasing onto the latest caseWhen branch and update conditional include expectations. Co-authored-by: Cursor <cursoragent@cursor.com>
a79e5eb to
7fa5b53
Compare
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +2.52 kB (+2.15%) Total Size: 119 kB 📦 View Changed
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 4.24 kB ℹ️ View Unchanged
|
Assert subquery-backed join lazy loading marks the concrete subscribed alias rather than the outer QueryRef alias. Co-authored-by: Cursor <cursoragent@cursor.com>
Stack
This PR is stacked on #1536 (
caseWhen) and usescase-whenas its base branch. Please review/merge #1536 first.Implementation plan: https://gist.github.com/samwillis/df7e2376c6c2bfd007e53dec797fca12
Summary
This PR adds multi-source
fromsupport to the DB query engine. It lets a query union multiple independent sources into one live query result without requiring an explicit join between those sources.What Changed
UnionFromIR node forfrom({ a, b, ... })with multiple sources.fromaccepts multiple collection or subquery sources, while joins still accept one source.wheresemantics after the union, while allowing users to pre-filter a branch by making it a subquery.from, including branch-dependent join keys viacoalesce.fromand ordering behavior in the live queries guide.Examples
Basic multi-source query:
Without
select, the result is an exclusive union:Pre-filter one branch with a subquery:
Join after a multi-source
fromwith branch-dependent keys:Guard branch-specific projections and includes with
caseWhenfrom #1536:Test Plan
pnpm vitest run packages/db/tests/query/multi-source-from.test.tspnpm --filter @tanstack/db buildpnpm vitest --run --typecheck tests/query/multi-source-from.test-d.ts --coverage.enabled=falsefrompackages/db; Vitest still reports unrelated existingincludes.test.tstype errors in the wider typecheck pass.Made with Cursor
Summary by CodeRabbit
New Features
Documentation
Tests
Made with Cursor