Request: ability to get subkey using chrome.storage.local.get()

164 views
Skip to first unread message

thdoan

unread,
Apr 18, 2018, 5:05:08 PM4/18/18
to Chromium-Extensions-Announce
Currently the get() method only accepts three parameters:

"A single key to get, list of keys to get, or a dictionary specifying default values (see description of the object)." (Source)

If you are storing a lot of data in chrome.storage, it can be more efficient to have the ability to get a subkey in some scenarios. Example

{
  "tom": { lots of data },
  "dick": {
    "fullname": "..."
    "phone": "...",
    "email": "...",
    "history": { lots of data }
  },
  "harry": { lots of data }
}

If I just want to retrieve Dick's email, I would prefer to get only the email subkey instead of the entire dick key, which contains a huge amount of data in history. It would be great if I could pull that off by doing something like this:

chrome.storage.local.get(dick.email, function(items) {
  // Do something with Dick's email and only Dick's email
  console.log('Dick\'s email is ' + items['email']);
});

wOxxOm

unread,
Apr 19, 2018, 10:19:41 AM4/19/18
to Chromium-Extensions-Announce
The storage doesn't index the object structure so it can't extract a subkey without extracting and parsing the entire value. That's how any storage works. You need to reorganize your object structure, for example use prefixes, to disperse it into separate keys.
Reply all
Reply to author
Forward
0 new messages