You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(db): clarify caseWhen, coalesce, manual transactions, and multi-endpoint behavior (#1544)
* docs(db): clarify caseWhen, coalesce, manual transactions, and multi-endpoint behavior
Address documentation feedback: add caseWhen operator docs, clarify coalesce
handles null/undefined, document manual transaction handler bypass semantics,
and warn about multi-endpoint Query Collection pitfalls. Fix categorization
of utility functions and reference index ordering.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: add changeset for docs clarifications
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs(db): mention unionAll as option for multi-endpoint collections
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs(db): replace redundant manual transaction example with explanatory prose
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Clarify documentation for caseWhen, coalesce, manual transactions, and multi-endpoint Query Collection behavior. Add utility function categorization and fix reference index ordering.
Copy file name to clipboardExpand all lines: docs/collections/query-collection.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -471,6 +471,27 @@ The query collection treats the `queryFn` result as the **complete state** of th
471
471
- Items in the query result but not in the collection will be inserted
472
472
- Items present in both will be updated if they differ
473
473
474
+
This is important when the same entity type can be loaded from multiple REST
475
+
endpoints. For example, do not point the same Query Collection at
476
+
`/api/documents/preview` for one load and `/api/documents/deleted` for another
477
+
unless each result represents the complete state for that collection
478
+
scope. A narrower endpoint can otherwise remove rows that were loaded from a
479
+
different endpoint.
480
+
481
+
For multiple endpoint or subset-loading use cases, choose the pattern that
482
+
matches your API semantics:
483
+
484
+
- Use `syncMode: 'on-demand'` when one logical collection can serve different
485
+
subsets of data. In this mode, query predicates (`where`, `orderBy`, `limit`,
486
+
and `offset`) are passed to your `queryFn` via `ctx.meta.loadSubsetOptions`,
487
+
letting you translate them into API parameters.
488
+
- Use separate Query Collections when endpoints represent distinct server scopes
489
+
whose results should not replace each other. Use `unionAll` to combine them
490
+
into a single query when you need a unified view across endpoints.
491
+
- Use direct writes such as `writeUpsert`/`writeBatch` for lower-level
492
+
incremental loading when you intentionally want to merge server responses into
493
+
the synced store yourself.
494
+
474
495
### Empty Array Behavior
475
496
476
497
When `queryFn` returns an empty array, **all items in the collection will be deleted**. This is because the collection interprets an empty array as "the server has no items".
The library provides string functions (`upper`, `lower`, `length`, `concat`), math (`add`), utility (`coalesce`), and aggregates (`count`, `sum`, `avg`, `min`, `max`). All are incrementally maintained. Prefer them over JS equivalents.
388
+
The library provides string functions (`upper`, `lower`, `length`, `concat`), math (`add`), utility functions (`coalesce`, `caseWhen`), and aggregates (`count`, `sum`, `avg`, `min`, `max`). All are incrementally maintained. Prefer them over JS equivalents.
389
389
390
390
```ts
391
391
// WRONG
@@ -398,9 +398,40 @@ The library provides string functions (`upper`, `lower`, `length`, `concat`), ma
0 commit comments