title: Invalid key path in IndexedDB: restrictions?
body: <p>I'm trying to create a really simple IndexedDB with some JavaScript, but it fails in the on handler already. Apparently the browser (Chrome 57) is not able to <a href="https://github.com/WebKit/webkit/blob/147e1b042ffe6bd831960cdae310ccfc58606e51/Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp#L132" rel="noreferrer">parse</a> the <code>keyPath</code> (in <a href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Basic_Concepts_Behind_IndexedDB" rel="noreferrer">Basic Concepts</a>) of my storage.</p>
  
  <p>I'm following more or less these simple examples: <a href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#Creating_or_updating_the_version_of_the_database" rel="noreferrer">MDN</a> or <a href="https://dev.opera.com/articles/introduction-to-indexeddb/" rel="noreferrer">Opera-Dev</a>.</p>
  
  <p>Suppose I want to store objects like this one in the DB:</p>
  
  <pre><code>{
      "1": 23, // the unique id
      "2": 'Name',
      "3": 'Description',
      "4": null,
      "5": null
  }
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>var sStoreNodes = 'nodes';
  var sIdFieldNode = '1'; // the important part
  
  // event is fired for creating the DB and upgrading the version
  request.onupgradeneeded = function(event)
  {
      var db = event.target.result;
  
      // Create an objectStore for nodes. Unique key should be the id of the node, on property 1. 
      // So ID will be the key!
      var objectStore =  db.createObjectStore(
          sStoreNodes,
          {
              // changing to a plain string works, if it is a valid identifier and not just a strigified number
              'keyPath'       : [ sIdFieldNode ],
              'autoIncrement' : false // really important here
          });
  };
  </code></pre>
  
  <p>The error message reads like:</p>
  
  <blockquote>
    <p>Uncaught DOMException: Failed to execute 'createObjectStore' on 'IDBDatabase': The keyPath option is not a valid key path.
        at IDBOpenDBRequest.CCapIndexedDB.request.onupgradeneeded</p>
  </blockquote>
  
  <p>I can also try to leave out the key path, but I'm wondering why this happens and want can I do about it, if I really need to use a (complex) key path.</p>
  
  <p>Regarding the spec:</p>
  
  <p>I'm not sure, whether <a href="https://www.w3.org/TR/IndexedDB/#dfn-valid-key" rel="noreferrer">this</a> can be applied here:</p>
  
  <blockquote>
    <p>A value is said to be a valid key if it is one of the following ECMAScript [ECMA-262] types: Number primitive value, String primitive value, Date object, or Array object.</p>
  </blockquote>
  
  <p>and what <a href="https://www.w3.org/TR/IndexedDB/#widl-IDBObjectStore-keyPath" rel="noreferrer">this</a> actually means:</p>
  
  <blockquote>
    <p>If the key path is a DOMString, the value [for getting the key path] will be a DOMString equal to the key path. If the key path is a sequence, the value will be a new Array, populated by appending Strings equal to each DOMString in the sequence.</p>
  </blockquote>
  
  <hr>
  
  <p><strong>Edit</strong> This works, if you don't use a stringified number, but a string instead, which is a valid identifier (beginning with a character [a-zA-Z]). So <code>'keyPath' : 'b'</code> is OK. I guess this is because this value is used for creating paths like <code>a.b.c</code>.</p>