W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2010

[IndexedDB] Behavior of IDBObjectStore.get() and IDBObjectStore.delete() when record doesn't exist

From: Jonas Sicking <jonas@sicking.cc>
Date: Mon, 8 Nov 2010 08:24:26 -0800
Message-ID: <AANLkTinSs1xaOoDzDtXF9DgqgenTHxvnDPjavkp0FMvm@mail.gmail.com>
To: Webapps WG <public-webapps@w3.org>
Hi All,

One of the things we discussed at TPAC was the fact that
IDBObjectStore.get() and IDBObjectStore.delete() currently fire an
error event if no record with the supplied key exists.

Especially for .delete() this seems suboptimal as the author wanted
the entry with the given key removed anyway. A better alternative here
seems to be to "return" (through a success event) true or false to
indicate if a record was actually removed.

For IDBObjectStore.get() it also seems like it will create an error
event in situations which aren't unexpected at all. For example
checking for the existence of certain information, or getting
information if it's there, but using some type of default if it's not.
An obvious choice here is to simply "return" (through a success event)
undefined if no entry is found. The downside with this is that you
can't tell the lack of an entry apart from an entry stored with the
value undefined.

However it seemed more rare to want to tell those apart (you can
generally store something other than undefined), than to end up in
situations where you'd want to get() something which possibly didn't
exist. Additionally, you can still use openCursor() to tell the two
apart if really desired.

I've for now checked in this change [1], but please speak up if you
think this is a bad idea for whatever reason.

[1] http://dvcs.w3.org/hg/IndexedDB/rev/aa86fe36c96e

/ Jonas
Received on Monday, 8 November 2010 16:25:21 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:41 GMT