<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>15796</bug_id>
          
          <creation_ts>2012-01-30 19:39:01 +0000</creation_ts>
          <short_desc>Specify how to extract a key when keyPath is an array</short_desc>
          <delta_ts>2012-03-02 15:42:17 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>Indexed Database API</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Odin Hørthe Omdal">odinho</reporter>
          <assigned_to name="Jonas Sicking (Not reading bugmail)">jonas</assigned_to>
          <cc>jonas</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>63347</commentid>
    <comment_count>0</comment_count>
    <who name="Odin Hørthe Omdal">odinho</who>
    <bug_when>2012-01-30 19:39:01 +0000</bug_when>
    <thetext>createObjectStore allows us to get a keyPath that is an array[1].

But there is as far as I can tell a lack of explicit mention of the possibility of the keyPath being an array later.

Does it belong in the steps for extracting a key path from a value? [2] Or possibly more fitting, a step up in the hierarchy like the steps for storing a record into and object store.

Anyway, keyPath as Array seems to be well specified for Indexes, both in IDBObjectStore.add [3] and in the steps for storing a record into an object store [4], but not so for keys, AFAICS.


Maybe change step 1 in &quot;steps for storing a record into an object store&quot; from:

&gt; 1. If store does use in-line keys and evaluting store&apos;s key path on value
&gt;    does yield a value, then set key to that result.

to:

&gt; 1. If store uses in-line keys and the store&apos;s key path is an [Array]
&gt;    then set /tempkey/ to a newly created empty Array. For each item in 
&gt;    the key path [evaluate] the item on value. If this does not yield a
&gt;    value continue to next step. Otherwise add the value to the end of 
&gt;    /tempkey/. When the array is finished set /key/ to /tempkey/.
&gt;
&gt; 2. Else if store does use in-line keys and evaluating store&apos;s key path 
&gt;    on value yields a value, then set key to that result.


Possibly changed to clearer and more succinct language :P


1. http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBDatabase-createObjectStore-IDBObjectStore-DOMString-name-IDBObjectStoreParameters-optionalParameters
2. http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#dfn-steps-for-extracting-a-key-from-a-value-using-a-key-path
3. http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBObjectStore-add-IDBRequest-any-value-any-key
4. http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#dfn-steps-for-storing-a-record-into-an-object-store</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63363</commentid>
    <comment_count>1</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-01-30 21:26:59 +0000</bug_when>
    <thetext>Yeah, I suspect this should be defined in the steps for evaluating a keyPath.

The way that we do this in Firefox is that we evaluate each item in the array individually. If any item fails yield a value which is a valid Key then we abort the whole algorithm and the keyPath-Array does not yield a value. If this is the keyPath for a objectStore then this results in throwing an exception. If this is a keyPath for an index then no entry is added to the index.

Simply skipping the item in the array which did not yield a keyPath doesn&apos;t seem correct to me. Consider the following example code:

store = db.createObjectStore(&quot;sales&quot;, { keyPath: [&quot;prodID&quot;, &quot;seller&quot;] });
store.put({ prodID: &quot;gummy-candy&quot;, seller: &quot;Sven&quot;, quantity: 10});
store.put({ prodID: &quot;chocolate-bar&quot;, seller: &quot;Stina&quot;, quantity: 5});
store.put({ seller: &quot;Lars&quot;, quantity: 5});

The first two entries create keys like: [&quot;gummy-candy&quot;, &quot;Sven&quot;] and [&quot;chocolate-bar&quot;, &quot;Stina&quot;].

If we were to use [&quot;Lars&quot;] as the key for the last entry, then it&apos;d look like &quot;Lars&quot; was the product ID and that a seller was missing. The right solution is to throw an exception for the last call as we don&apos;t have a sensible key to use.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63393</commentid>
    <comment_count>2</comment_count>
    <who name="Odin Hørthe Omdal">odinho</who>
    <bug_when>2012-01-31 09:43:26 +0000</bug_when>
    <thetext>Yes, that was how I envisioned it as well. I see I goofed up in my example proposal; it shouldn&apos;t be &quot;continue to next step&quot; but rather &quot;set error attribute ... and terminate the algorithm&quot;. :-)

Putting the array-specific parts into the algorithm &quot;steps for extracting a key from a value using a key path&quot; seems a bit wrong too, because you won&apos;t be able to just run those steps on a single keyPath. But maybe that&apos;s of no value in the spec anyway.

The array-specific looping-part could be put in 3.1.5 Key Path [1], but it seems a bit out of place there as it&apos;d benefit from some more algorithmic steps. That&apos;s why I put it in the &quot;steps for storing a record into an object store&quot;.

Those steps would at least need some added error handling if the &quot;steps for extracting a key from a value using a key path&quot; handles the keyPath-Array itself.


1. http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#dfn-evaluate-key-path</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64882</commentid>
    <comment_count>3</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-03-02 04:03:15 +0000</bug_when>
    <thetext>I&apos;ll take this one.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64915</commentid>
    <comment_count>4</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-03-02 15:42:17 +0000</bug_when>
    <thetext>Done.

I specified it as part of the keyPath evaluation steps since that way it will automatically be specified both when a keypath-array is used in an objectStore, and when a keypath-array is used in an index.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>