-
-
Notifications
You must be signed in to change notification settings - Fork 648
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
Dexie.js always uses WebSQL even when IndexedDB is fully supported #342
Comments
If the shim is there, Dexie has assumed you'd prefer using it. This has been due to the incomplete indexedDB implementation in Safari 9 that has been practically almost unusable. Now with Safari 10, this need to change, so thanks for bringing it up. You can still force using the native indexedDB by setting : Dexie.dependencies.indexedDB = indexedDB;
Dexie.dependencies.IDBKeyRange = IDBKeyRange; |
Thanks @dfahlander. Now I understand why I get this behavior. The shim's documentation tells that it does nothing in browsers that natively support IndexedDB but it does not seem to be the case since in Firefox the I noticed a difference between the shim's documentation and Dexie.js code regarding the use of the shim. The shim suggests to use IndexedDB when it is available whereas Dexie.js uses the shim first if it is available. Is this aimed at fixing the issue with Safari 9 you are mentionning? I expected the shim or maybe Dexie.js to provide always the most appropriate implementation. I can force the use of IndexedDB as you suggested but who better than the shim knows that the current browser supports IndexedDB? I am going to investigate this issue and maybe discuss about that in the shim's project. |
I just come to report an issue in the shim project to get more precisions regarding its behavior: indexeddbshim/IndexedDBShim#263. |
See also #148. |
There's also a historical reason of Dexie's behavior : the shim suffered from not being able to shim Safari 9 once it had indexedDB already. It was not possible to useShim because Safari complained about replacing indexedDB. There were simply no way to use the shim through window.indexedDB. Had to check for window.shimIndexedDB. Now we have the opportunity to change Dexie's behavior in 2.0 beta. Would that be good or bad? Apps that rely on the current behavior would suddenly go over to using the real indexedDB instead. I need advice here ;) |
Thanks for your responses! I am getting gradually a better picture of the issue. I could solve my issue by telling Dexie.js to use the shim or not. As I am in an ionic / Cordova application running on Android and iOS only, I can detect easily the OS type and version thanks to an ionic API. Then I configure Dexie.js according to what Can I use says. I will test that on various devices to confirm it works. If I change this heuristic later, in some devices the database used may change and that will result in a total data loss. Indeed, it will be the same if Dexie.js changes its behavior regarding the shim in version 2. In my case I don't care because I use IndexedDB as a cache storage but I assume it is not the case for all Dexie.js users. Maybe if that has to change it would be nice to let the ability to choose which IndexedDB implementation to use at it is currently the case and provide the configuration that corresponds to the 1.x behavior in the migration guide? If that has to change in Dexie.js 2, in my own opinion, it would be nice to find a way to use always the most accurate implementation:
As far as I know, the shim doesn't offer any way to get this more accurate implementation without detecting yourself the browser type:
I will try to find a solution thanks to this ticket: indexeddbshim/IndexedDBShim#263. |
I am 👍 on making Dexie 2.0 prefer native IndexedDB. |
You may be interested in my reply at indexeddbshim/IndexedDBShim#263 (comment) |
@brettz9 Thanks for the detailed explanation. I'm removing the faulty behavior in Dexie 2.0.0-beta.11 - (won't no more use shimIndexedDB just because it is present). Will just use window.indexedDB and assume the shim does the job to check if it is needed. This may cause disturbance for Dexie users that assumes Dexie's previous behavior. People that have included the shim may expect Dexie to pick it up without calling __useShim() also for browsers where the shim is optional (as with IE/Edge). So I might need to be clear on this in the release notes and the deprecations page. |
I am developing a Cordova application and I need the application to be able to work offline.
Dexie.js offers a great and well documented API to interact with IndexedDB. As Dexie.js is able to use IndexedDBShim for devices that do not support IndexedDB, it seems to be a very good tool given my constraints.
I did some experiments with Dexie.js and IndexedDBShim and I realized that Dexie.js always uses the shim. It even tries to use the shim on Firefox that supports IndexedDB but not WebSQL. In Chrome it works but it uses WebSQL (it would be probably better to use IndexedDB) and in Firefox it does not work at all since it does not support WebSQL.
Here is how I load both libraries:
I create a Dexie object with default options:
Note that I do not call
window.shimIndexedDB.__useShim()
.I would expect Dexie.js to use shimIndexedDB only when the device does not support IndexedDB.
I probably misused either Dexie.js or shimIndexedDB.
Does anybody else encounter this behavior? Can anybody help me?
Thanks!
The text was updated successfully, but these errors were encountered: