PSA: New Promise-based IndexedDB.jsm module

Kris Maglione kmaglione at mozilla.com
Sun Mar 26 02:27:19 UTC 2017


A couple of weeks ago, I added a new Promise-based IndexedDB 
helper module as part of some performance work I was doing:

http://searchfox.org/mozilla-central/source/toolkit/modules/IndexedDB.jsm

If you've been avoiding IndexedDB because of the verbose and
difficult-to-work-with API, I encourage you to give it a try. There are
a lot of advantages to using IndexedDB for storage, particularly the fully 
async API and use of structured clone for data serialization. With this 
module, a basic database access is as simple as:

  let db = await IndexedDB.open(
    "fooDB", {storage: "persistent", version: 1}, db => {
      db.createObjectStore("foo");
    });

  await db.objectStore("foo", "readwrite")
          .set("bar", {baz: "quux"});

  let val = await db.objectStore("foo").get("bar");

Please let me know if you have any questions or suggestions.

-Kris



More information about the firefox-dev mailing list