-
Notifications
You must be signed in to change notification settings - Fork 115
Add optional compareOptions to the Collection Config which act as col… #762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 464c74c The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +346 B (+0.42%) Total Size: 83.3 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.34 kB ℹ️ View Unchanged
|
e4a6188 to
ffe08e9
Compare
…lection-wide config and allow queries to override those.
fa1e85e to
57bfe3d
Compare
packages/db/src/types.ts
Outdated
| /** | ||
| * Specifies how to compare data in the collection. | ||
| * This should be configured to match data ordering on the backend. | ||
| * E.g., when using the Electric DB collection these options | ||
| * should match the database's collation settings. | ||
| */ | ||
| compareOptions?: StringSortOpts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KyleAMathews this is a new collection config option, you may have some to say on naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit ambiguous at the collection level what is compared — defaultCollation or defaultStringCollation is more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, went for defaultStringCollation and renamed StringSortOpts type to StringCollationConfig (cc @KyleAMathews @samwillis)
|
@kevin-dp as discussed we need to traverse the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
#762) * Add optional compareOptions to the Collection Config which act as collection-wide config and allow queries to override those. * Fix import * changeset * Ran prettier * update docs * Live queries inherit compare options from collection in the FROM clause * Explicit compare options for live queries * Rename compareOptions to defaultStringCollation in the collection config and live query collection config * Docs update --------- Co-authored-by: Sam Willis <sam.willis@gmail.com>
This PR adds support for collection-wide string ordering/locale configuration. It is possible to override these in a specific query by providing specific
compareOptionsin the query'sorderByclause. The priority is as follows (high to low):compareOptionscompareOptionsif none specified in querycompareOptionswhen creating the collectionThe idea behind providing collection-wide locale configuration is that most applications should use the same locale configuration as their backend. This is needed because tanstack DB does a mix of loading ordered data from the backend and loading ordered data that is available locally. Hence, the local ordering must be the same as the one on the backend otherwise we get inconsistent behavior.
Implementation
High-level
StringSortOptsin the collection itself. If none are provided, we store the default locale configuration.orderByclause with defaults for the locale, if no locale is specified, we keep them undefined in theorderByclauseorderByclause's config and the collection's config. If theorderByclause specifies locale configuration, we use that one. Otherwise, we use the locale configuration from the collection.Details