My question is specific to dojo store, but I think the issue would be similar with html5 indexedDB.
I deal with data sets stored in a matrix, for example sports league results. Each item looks like this:
host:"Team3", visitor:"Team8", result:"3-1", season:"2012"
My issue is that dojo store (or indexedDB) require a key. In my case I don’t have one, as none of the properties is specific to the item.
What would be the best way to deal with this? I have considered two options but I don’t like them:
- Add an id property to each item (for example incremental number)
-
Create a hierarchy in my data, for example:
{host:”Team1″, results:[
{visitor:”Team2″,result:”1-1″,season:”2012″},
{visitor:”Team3″,result:”1-2″,season:”2012″},
…]
In both cases, the structure is heavier for no benefit (other than matching the specifications). Is there a better way?
I can only speak for indexeddb, but if you don’t need to care about a key and you need one. In this case I would choose for an autoIncrement key without a key path. In this case you will have a key, and this key won’t be added inside your object. If you need the key, than set the key path to Id. This way the Id property will be added to your object with the autoIncrement key.