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

What is the use case for storing undefined in an object-store?


Cheers,
Keean.

On 8 November 2010 20:59, Jonas Sicking <jonas@sicking.cc> wrote:

> On Mon, Nov 8, 2010 at 12:02 PM, Keean Schupke <keean@fry-it.com> wrote:
> > Hi,
> >
> >> > I don't understand that.
> >> > with the proposal, undefined clearly means the entry does not exist as
> >> > there is no way to put an undefined into the object store (as
> >> > .put(undefined, key) deletes the entry).
> >>
> >> The confusing part is that a function called 'put' actually deletes
> >> something, especially since we also have a 'delete' function.
> >
> > Sure, you could get rid of the delete function :-) I think the meaning of
> > "put(undefined, key)" is pretty clear.
>
> I guess we'll have to agree to disagree on that one :)
>
> My concern with something like this is that we'll see code do stuff like:
>
> function myStoreFunction(objectStoreName, key, value) {
>  os = db.transaction([objectStoreName]).objectStore(objectStoreName);
>  if (value === undefined) {
>    os.put(null, key);
>  }
>  else {
>    os.put(value, key);
>  }
> }
>
> which does not seem like a net win for anyone.
>
> >> I would put the question this way: What problem are you trying to
> >> solve? If the problem is that people can't store "undefined" and then
> >> tell "undefined" apart from "not there" then your proposal doesn't
> >> solve that problem as "undefined" can't be stored at all.
> >
> > Precisely, the solution I am proposing is based on disallowing storing of
> > 'undefined'. What does it mean to store 'undefined' anyway? People can
> still
> > use null.
>
> Wait, your solution doesn't solve the above described problem. The
> described problem was
>
> People can't store "undefined" and then tell "undefined" apart from
> "not there" then your proposal doesn't solve that problem as
> "undefined" can't be stored at all.
>
> Your solution doesn't solve that problem.
>
> / Jonas
>

Received on Monday, 8 November 2010 21:41:51 UTC