[indexedDB] is setVersion() going to be removed or deprecated in Chrome 17+ ?

546 views
Skip to first unread message

Laurent Perez

unread,
Jan 3, 2012, 9:27:26 AM1/3/12
to Chromium-discuss
Hi

Since Chromium doesn't yet implement onupgradeneeded (http://
code.google.com/p/chromium/issues/detail?id=108223), I'm currently
using the setVersion method with a manual db version check to update
my database stores.

Is setVersion() still going be supported in future releases ?

Thanks,
laurent

Joshua Bell

unread,
Jan 3, 2012, 12:13:29 PM1/3/12
to l.lau...@gmail.com, Chromium-discuss
It is likely that when we remove the "webkit" prefix we'll only support the onupgradeneeded approach and drop setVersion(). That's a ways off though.

We will support setVersion for several more versions of Chrome at least. We would also like to support a transition period where both setVersion and onupgradeneeded are supported, but we haven't fully confirmed that the spec would allow that behavior.

To be future-proof and support other browsers, the following (UNTESTED!) pattern should work:

indexedDB = indexedDB || webkitIndexedDB || mozIndexedDB || msIndexedDB;
var DESIRED_VERSION = 1;
var openRequest = indexedDB.open('db-name', DESIRED_VERSION);

// Always anticipate blocked events
openRequest.onblocked = function (e) {
  ...
};

// Support newer API:
openRequest.onupgradeneeded = function (e) {
  var transaction = openRequest.transaction;
  doUpgrade(e.oldVersion, transaction);
};

openRequest.onsuccess = function() {
  var db = openRequest.result;

  var oldVersion = Number(db.version);
  if (oldVersion !== DESIRED_VERSION) {

    // Support older API:
    if (!db.setVersion) { throw new Error(); }
    var versionRequest = db.setVersion(ver);
    versionRequest.onsuccess = function (e) {
      var transaction = versionRequest.result;
      doUpgrade(oldVersion, transaction);
      useDatabase(db);
    };

  } else {
    useDatabase(db);
  }
};

function doUpgrade(oldVersion, transaction) {
  ...
}

function useDatabase(db) {
  ...
}

Laurent Perez

unread,
Jan 3, 2012, 5:02:54 PM1/3/12
to Chromium-discuss
Thanks Joshua, things are much clearer now :)

rgds,
laurent


On 3 jan, 18:13, Joshua Bell <jsb...@chromium.org> wrote:
Reply all
Reply to author
Forward
0 new messages