Hi,

I once met a similar need: a simple key/storage API for my addon. I
ended up writing a "SimpleStorage" module that uses an underlying SQLite
database. I'm pretty sure I fell into most of the pitfalls of using
SQLite without being a guru, but here's the link for posterity:
- sample usage
<https://github.com/protz/thunderbird-stdlib/blob/master/tests/test_SimpleStorage.js>
(line 50-65)
- implementation
<https://github.com/protz/thunderbird-stdlib/blob/master/SimpleStorage.js>

The library exposes a has/set/get API, and uses iterators with a lot of
yield's to allow the client to write their code in a style that looks
synchronous but that actually isn't (see sample usage). I assume the new
hotness now is using a promises-style API instead of ES6
iterators/generators, but I'm sharing this in case anyone wants to check
it out. It's being used heavily by the Thunderbird Conversations addon
(~100 000 ADU).

Speaking as an addon author, I would definitely embrace anything that
offers such a dead-simple get/set/has API, even more so if it's
advertised as "doing things right". If someone were to bundle a JSM
somewhere in Gecko that exposes a similar API on top of IndexedDB, that
would be great relief for addon authors.

jonathan

On 04/27/2013 05:42 AM, bent wrote:
> IndexedDB is our answer for this for JS... C++ folks are still pretty
> much on their own!
>
> IndexedDB handles indexing (hence the rather awkward name),
> transactions with abort/rollback, object-graph serialization (not just
> JSON), usage from multiple tabs/windows/components/processes
> simultaneously, data integrity guarantees, and easy single-copy file/
> blob support. It's also completely asynchronous (and read-only
> transactions run in parallel!), and one day soon it will be available
> in Workers too. We're using it extensively in B2G (it's the only
> storage option, really) and it's easily usable from chrome too (with a
> two line bit of Cc/Ci init code). IE and Chrome both implement it and
> we all have it available without a prefix because the API (v1) is
> pretty much frozen.
>
> What we've heard from a lot of JS developers (gaia folks included),
> though, is that this feature set is more than some want or need. They
> don't want to worry about indexes or transactions or serializing
> complex objects. Luckily we anticipated this! Our aim was to provide a
> sufficiently powerful tool such that we could build complex apps (e.g.
> B2G's email app, ping asuth for details!) as well as simple key-value
> stores (e.g. gaia's async_storage, mostly written by dflanagan I
> think). Someone even implemented an early version of Chrome's
> filesystem API on IndexedDB...
>
> Nevertheless, I (and others) think it's clear that the big thing we
> screwed up on is that we didn't release a "simple storage" wrapper
> alongside IndexedDB. I think we expected this sort of thing to appear
> on its own, but so far it hasn't. Sorry :(
>
> So now we're working on wrappers. https://github.com/mounirlamouri/storage.js
> is one in-progress example. I think there is another as well but the
> link escapes me at the moment. In any case it should be trivial to do
> something very similar as a JSM. (We already have an
> IndexedDBHelper.jsm for more complicated databases that do actually
> want control over tables and indexes.)
>
> Hopefully IndexedDB meets most people's needs... That's what we tried
> to build here, after all. The need to sprinkle some sugar here and
> there is completely expected and very much encouraged. Please feel
> free to ping me over irc or email or here on the list if anything is
> unclear or difficult. (Of course there are definitely other folks that
> are involved here but I don't want to volunteer them without their
> consent!)
>
> -bent
>
> P.S. The "experimental" mark in MDN is outdated, and very unfortunate.
> We should remove that ASAP.
> _______________________________________________
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to