dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.69k stars 641 forks source link

Error on iPad when more than one store #68

Closed ghost closed 9 years ago

ghost commented 9 years ago

I seem to be struggling with Dexie.js on an iPad. Can anyone please help me figure out why this code is seems fine on chrome but won't work on an ipad? If i comment out the folder store, it seems to work fine. I've even tried with the newest version uploaded 3 days ago without any luck.

<script>
var db = new Dexie('test');
db.version(1)
 .stores({
  identity: 'id,contactId',
  folder: 'folderId, folderName'
});

db.open()
 .then(function() {return db.identity.put({id: 1, contactId: 819})})
 .catch(function (error) {
  $('#error1').html(JSON.stringify(error));
});

$(function() {
 db.identity.where('id').equals(1).first(
  function(identity) {
  $('#info').html(identity.firstName);
 }
 ).catch(function (error) {
  $('#error2').html(JSON.stringify(error));
 });
});
</script>
<div id="info">0</div>
<div id="error1">0</div>
<div id="error2">0</div>

The error that comes up is NotFoundError: DOM IDBBatabase Exception 8, line 529, column 87

dfahlander commented 9 years ago

IndexedDB has a buggy implementation on Safari when it comes to multiple object stores. I've tried to do my best to work around some of the bugs. One of the bugs is that multiple stores cannot have primary keys that collide. This is something that could be worked around, but not as part of Dexie because it would bloat the library.

However, if I get you correct, you cannot even define multiple object stores. This is something that could be fixed I believe. Could you see at which line in Dexie.js it fails? (If you see a stack on the catched error, or if you could debug it and see if it throws an exception somewhere)

ghost commented 9 years ago

The error says: The error that comes up is NotFoundError: DOM IDBBatabase Exception 8, line 529, column 87

Which appears to be this line: adjustToExistingIndexNames(globalSchema, idbdb.transaction(safariMultiStoreFix(idbdb.objectStoreNames), READONLY));

ghost commented 9 years ago

I've tried using the polyfill shim as well and force use on safari using

window.shimIndexedDB.__useShim()

With no luck. Is there an issue with using the shim with Dexie.js or is safari just hopelessly bugged?

dfahlander commented 9 years ago

Need to adjust the polyfill as describe in Issue #63 to make it work.

dfahlander commented 9 years ago

Not needed to adjust the IndexedDBShim anymore. See #77 !