I've been reading all around the MDN, but I get stuff like:
keyPath
The key path for the index to use. Note that it is possible to create an index with an emptykeyPath
, and also to pass in a sequence (array) as akeyPath
.
Well, no s@!t, keyPath
is a key path. But what is that?
In all examples, it's the same thing as the name of the column (or index, as they call it):
objectStore.createIndex("hours", "hours", { unique: false });
objectStore.createIndex("minutes", "minutes", { unique: false });
objectStore.createIndex("day", "day", { unique: false });
objectStore.createIndex("month", "month", { unique: false });
objectStore.createIndex("year", "year", { unique: false });
They say that you can pass:
- An empty string -
""
- A valid JavaScript identifier (I assume this means valid JS variable name)
- Multiple javascript identifiers separated by periods, eg:
"name.name2.foo.bar"
- An array containing any of the above, eg.:
["foo.bar","","name"]
I can't imagine what purpose does this serve. I absolutely do not understand what keyPath
is and what can I use it for. Can someone please provide example usage where keyPath
is something else than the name of the column? An explanation what effect do values of keyPath
have on the database?