axemclion / jquery-indexeddb

An IndexedDB Plugin for Jquery.
Other
195 stars 70 forks source link

deprecated modes #15

Closed scott-davidjones closed 11 years ago

scott-davidjones commented 11 years ago

Hi,

first off, loving this plugin - tried to build my own db handler and was having loads of issues with it being asyncronous (need the db to load before anything else..)

although the plugin works im getting a lot of these: Numeric transaction modes are deprecated in IDBDatabase.transaction. Use "readonly" or "readwrite".

took a look at your code but cant see where numeric values are being called.. using chrome Version 22.0.1229.92 m

still works but would be ace if i could get rid of those warnings..

scott-davidjones commented 11 years ago

also if it helps i am already calling the plugin via this: $.indexedDB("db").objectStore("objectStore", "readwrite" );

i am using "readwrite"/"read" as i though that these were just being passed though but it appears not..

axemclion commented 11 years ago

Regarding your first question, the way modes are used is directly from the constants defined by the browsers. The browsers define numeric constants and hence the warning. I am guessing that the numeric values will be replaced with text values by the browser, and this will go away. Doing it this way ensures that the plugin works for older versions of browsers too

scott-davidjones commented 11 years ago

hmm im not sure this is a browser issue.. when i was writing my own db handler following: https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB

I was not getting any of these issues.. ALso from what i can see in your code do you not just pass the users param straight through?

eg you could use wither of these and let the browser decide if its right or wrong:

$.indexedDB("db").objectStore("objectStore", "readwrite" );

$.indexedDB("db").objectStore("objectStore", 1 );

$.indexedDB("db").objectStore("objectStore", true );

it looks like you are explicitly saying the user has to pass a number, as per line 481:

me.transaction(storeName, typeof mode === "number" ? mode : IDBTransaction.READ_WRITE).then(function(){

if i do the following:

$.indexedDB("db").objectStore("objectStore", "readwrite" ).index("ID").each();

it all works but i still get the following warning:

Numeric transaction modes are deprecated in IDBDatabase.transaction. Use "readonly" or "readwrite".

i would assume that becuase i am passing in a string and not a number then IDBTransaction.READ_WRITE should be used, thus the browser would use "readwrite" instead of 1 but this does not seem to happen..

axemclion commented 11 years ago

I think a simply replacing that check for a number, but string would work. However, note that for compatibility with older browsers, is it best to use the constant IDBTransaction.READ_WRITE, or as exposed in the jquery library - $.indexedDB.IDBTransaction.READ_WRITE. I guess this constant it too long.

axemclion commented 11 years ago

Changed this in commit eed4ec9456fb17327da0b8ca931fae593c09f88d. If the user now passes modes like $.indexedDB(DB.NAME).objectStore(DB.OBJECT_STORE_1, "readwrite").count(), they are passed through to the plugin, and no warnings are found.

However, to support older versions of chrome, the mode used is window.IDBTransaction || window.webkitIDBTransaction;. These constants are also defined in the newer browsers but only result in warnings.

scott-davidjones commented 11 years ago

most excellent :)

will test this out tomorrow - thanks :)