Exploring a Dexie-native collection integration for TanStack DB #1974
dfahlander
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi! I’m David Fahlander, author of Dexie.js.
I’ve been exploring what a first-class integration between Dexie and TanStack DB could look like. I’m interested in building a small PoC, but I would first like to make sure that its ownership model aligns with TanStack DB’s intended extension points.
Existing work
I’m aware of the earlier work in #575 and #576 and the existing tanstack-dexie-db-collection community package.
I don’t want to disregard or unnecessarily duplicate that work, and I would be happy to collaborate with @HimanshuKumarDutt094.
TanStack DB already provides a capable SQLite/OPFS persistence stack through #865 and #1358. For browser-focused applications, a Dexie-backed persistence implementation could potentially offer a lighter, browser-native alternative that does not require SQLite/WASM and a dedicated SQL worker.
My primary interest, however, goes beyond providing another persistence backend. The integration should preserve Dexie as an application-facing database that can be queried and mutated directly and extended through addons such as Dexie Cloud and y-dexie.
I would therefore like to understand whether TanStack DB’s persistence contract can support an independently mutable, application-facing database, or whether that ownership model requires a custom collection adapter.
Intended ownership model
The goal is for Dexie to remain the authoritative local database and public mutation API, while TanStack DB provides a normalized, reactive, relational in-memory view over selected subsets of that database.
In this model:
Dexieinstance and existing tables.table.put(),bulkPut(),db.transaction(),where(...).modify()andwhere(...).delete().TanStack DB would not need to reproduce every Dexie API or understand Yjs documents.
For example, an application could use TanStack DB to query documents and relationships while obtaining the actual
Y.Docthroughy-dexie. Similarly,where(...).modify()could remain a Dexie operation as long as the resulting changes are reflected in the relevant TanStack DB collections.The important point is that Dexie remains visible and directly usable as the application’s local database rather than becoming only an internal storage driver for TanStack DB.
Possible PoC
A first PoC could expose something along these lines:
Internally, it could:
loadSubset()calls to translate TanStack DB predicates, ordering and limits into one-shot Dexie queries.storagemutatedevent for changes made in other tabs or workers.This would allow TanStack DB to provide joins, incremental view maintenance and framework reactivity without requiring an application to abandon its existing Dexie data model or mutation APIs.
Questions about the appropriate integration point
Before choosing between the persistence API and a custom collection adapter, I would appreciate guidance on the following.
1. Which extension point matches this ownership model?
Can
persistedCollectionOptionsand its persistence contract represent an externally owned and independently mutable local database with its own transaction model and change feed?If the persistence contract can preserve this ownership model, I’m open to building on it. Otherwise, would this be better implemented as composed collection options or a custom collection adapter whose sync layer materializes data from Dexie into TanStack DB?
2. How should external mutations be propagated?
When a row is changed directly through Dexie, what is the preferred supported way to reflect that change in a TanStack DB collection?
Can an adapter safely emit insert, update and delete messages through the collection sync interface? For coarse invalidation, is
truncate()followed by reissuing active subset demands an intended and stable mechanism?3. Which subset responsibilities belong to TanStack DB core?
Ideally, TanStack DB would own active query demand, request deduplication, subset lifetimes and eviction from the in-memory collection.
The Dexie adapter would translate
loadSubset()into a database query and report subsequent changes, without independently maintaining a second query cache. Is that consistent with the current adapter contract?Next step
If this ownership model makes sense, I would be happy to build a focused PoC covering:
I would also be interested in contributing adapter conformance tests if there is a preferred test contract for collection implementations.
Does this sound like a useful integration direction, and which TanStack DB abstraction would you recommend for preserving this ownership model?
All reactions