javascript - Invalid key path in IndexedDB: restrictions? -


i'm trying create simple indexeddb javascript, fails in on handler already. apparently browser (chrome 57) not able parse keypath (in basic concepts) of storage.

i'm following more or less these simple examples: mdn or opera-dev.

suppose want store objects 1 in db:

{     "1": 23, // unique id     "2": 'name',     "3": 'description',     "4": null,     "5": null } 

here code:

var sstorenodes = 'nodes'; var sidfieldnode = '1'; // important part  // event fired creating db , upgrading version request.onupgradeneeded = function(event) {     var db = event.target.result;      // create objectstore nodes. unique key should id of node, on property 1.      // id key!     var objectstore =  db.createobjectstore(         sstorenodes,         {             // changing plain string works, if valid identifier , not strigified number             'keypath'       : [ sidfieldnode ],             'autoincrement' : false // important here         }); }; 

the error message reads like:

uncaught domexception: failed execute 'createobjectstore' on 'idbdatabase': keypath option not valid key path. @ idbopendbrequest.ccapindexeddb.request.onupgradeneeded

i can try leave out key path, i'm wondering why happens , want can it, if need use (complex) key path.

regarding spec:

i'm not sure, whether this can applied here:

a value said valid key if 1 of following ecmascript [ecma-262] types: number primitive value, string primitive value, date object, or array object.

and this means:

if key path domstring, value [for getting key path] domstring equal key path. if key path sequence, value new array, populated appending strings equal each domstring in sequence.


edit works, if don't use stringified number, string instead, valid identifier (beginning character [a-za-z]). 'keypath' : 'b' ok. guess because value used creating paths a.b.c.

here definition of key path, spec:

a key path domstring or sequence defines how extract key value. valid key path 1 of:

  • an empty domstring.
  • an identifier, domstring matching identifiername production ecmascript language specification [ecma-262].
  • a domstring consisting of 2 or more identifiers separated periods (ascii character code 46).
  • a non-empty sequence containing domstrings conforming above requirements.

for string containing integer, first, third, , fourth options not apply. second, have see what identifiername is, little complicated, has start letter, underscore, or dollar sign. means string containing integer not valid key path.

if have object primary key in field name string containing integer, can either rename field or not use key paths (in case have manually specify key second argument idbobjectstore.add , idbobjectstore.put).

you linked the definition key, defines valid values key can have (like object {a: 1} key path 'a' key 1, valid).

the other thing linked to key paths a.b.c referencing {a: {b: {c: 1}}}.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -