Running Asynchronous Queries alongside updating Dynamic Schema #1950
Replies: 1 comment 1 reply
-
IndexedDB isn't tailored to allow ongoing queries while updating schema but we're trying to work aroud it in Dexie and we have the possibility to do so because of how transactions are declared - we may catch DatabaseClosedError under the hood and rerun transactions, but this is currently only implemented for working around certain bugs in the browsers and not yet implemented for the use case you are describing. However, schema updating is rigorously protected against race conditions in IndexedDB itself so two "simultanous" schema updates cannot happen because each of them have to perform an upgrade transaction that locks the database. However, if closing the DB during an upgrade transaction, that upgrade transaction might cancel and never be performed so we would need to take special care of that situation in Dexie if supporting this use case. |
Beta Was this translation helpful? Give feedback.
-
I am running multiple asynchronous queries across the site. Among these there are few queries which some time have to dynamically update schema and version of database and when they do, they have to close database connection with db.close() which in turn stop all other queries and throw errors like "DatabaseClosedError". Because of multiple asynchronous queries, I have no clue when certain queries can trigger schema update.
What is the proper way to handle such situation? Because even if I use flags when updating schema, it will still cause problem for already running/in-process queries to close connection if sudden schema update is triggered.
Can Dexie or IndexedDB run into race condition if certain field of table is updated at the same time?
Do I need to open and close db connection for each query or I can run multiple asynchronous queries on single connection like opening database at the beginning and running all queries on it throughout the website without closing it except for schema update?
Beta Was this translation helpful? Give feedback.
All reactions