browser-db-sqlite-persistence: a way to queue app SQL behind the persistence's transactions on a shared database
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Feature
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- sqlite, typescript, wasm
Rechercherichtung
Start by reading wa-sqlite-driver.ts and the package entry's exports field, then trace how BrowserWASQLiteDriver.transaction() queues work for a shared database handle. Decide which supported API shape safely queues application SQL behind persistence transactions; the issue lists exporting the driver, adding a persistence method, or documenting direct execution as off-limits. Done means the chosen approach prevents application statements from being rolled back unexpectedly.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
- I've checked this against the latest DB packages (
@tanstack/[email protected]from npm, andmainatd054a772)
Describe the feature
I'd like a supported way to run my own SQL on the database handle that createBrowserWASQLitePersistence uses, queued behind the persistence's transactions.
Why
We keep app metadata in our own tables in the same OPFS database as our persisted collections: a sync cursor and an outbox of pending mutations. These tables are separate from the persistence's tables and never touch them. We send statements to them with database.execute() on the handle from openBrowserWASQLiteOPFSDatabase(), which is the handle we also pass to createBrowserWASQLitePersistence.
BrowserWASQLiteDriver.transaction() runs BEGIN IMMEDIATE, then several awaited execute calls, then COMMIT or ROLLBACK. Its queue (databaseExecutionStates, a WeakMap keyed by the database object) orders only the driver's own work. A statement we send to the same handle between that BEGIN IMMEDIATE and the COMMIT runs inside the driver's transaction, on the same connection. If the driver then rolls back, our write is rolled back with it, even though our execute() call already resolved.
For us this can silently drop rows from our outbox. We add rows to it and then set a "done" marker in a second statement. If a rollback lands between the two statements, the marker is kept and the rows are not. It needs a SQL error inside the driver's transaction, such as a full storage quota, so it's rare. Our callers can't detect it.
We found this by reading the driver code, not from a field report. We haven't built a standalone reproduction.
What we tried
- Queueing behind the driver ourselves isn't possible.
BrowserWASQLiteDriveris exported fromwa-sqlite-driver.ts, but not from the package entry: theexportsfield lists only., the wasm and the worker. - We could track the transaction ourselves. We could wrap the handle we pass in, watch for
BEGIN IMMEDIATE,COMMITandROLLBACK, and hold our statements until no transaction is open. That depends on the driver's SQL text, which isn't a public contract. - A second connection is too heavy. It would mean a second worker and wasm instance per tab, plus lock contention on the file.
Possible shapes
Any of these would work for us:
- Export
BrowserWASQLiteDriverfrom the package entry. A driver we construct on the same handle shares theWeakMapqueue, so itsrunandtransactioncalls are ordered with the persistence's work. - Add a method to the persistence, such as
persistence.runExclusive(fn)or adriveraccessor, that runs a callback in the same queue. - Document the shared handle as off-limits for direct
execute()calls, so other users don't run into this.
Option 1 looks smallest, since the queue already works per database object.
Context
The app is a local-first sync client. Each tab opens one OPFS database per data partition. Collections use persistedCollectionOptions with createBrowserWASQLitePersistence. Our own tables live next to the persistence's tables and use their own names.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 4k
- Forks
- 280
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 139
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/db
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag
-
OfflineExecutor.dispose() never settles pendingTransactionPromisesEvtl. wieder frei @Claire-ovo hat das vor 12 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
TanStack/db#2254 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Two @tanstack/db tests time out under CPU load because a cold module import counts against the 5 s default timeoutEvtl. vergeben @jp-knj hat das vor 10 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Add: ESP 2 ROOffenapproved check:passed streams:add
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
ipaas: Configure form shows "Deploy to apply." and "Overrides selected Link" when they don't applyOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
wso2/integration-control-plane#1118 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
UTDNebula/utd-notebook#311 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag