-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to get many items (aka. getItems()) #21
Comments
For what it's worth, rather cryptically, memcache's |
With IndexedDB, the undocumented |
fwiw, websql obviously also supports bulk get. |
@kyoshino thanks a bunch! I didn't know. I don't like the "moz" part of that but I'm guessing that can be solved with just being careful and falling back on something else if it's not available. |
Maybe it's a bit unrelated, or overkill for localForage, but it would be nice if LF supported queries like WebSQL and IndexedDB already do. Or would you guys recommend another aggregator if I want queries? |
Translating actual SQL queries to something that would work in IndexedDB or localStorage sounds like it would be a pain, and not really the point of this library. I like the simple localStorage API, but I'm happy to extend it with things like I think the queries would be overkill. |
"Translating actual SQL queries"?? No, all I want is something like |
How would getitems work? Currently using LF and I have a key that is USERID:ORDER and storing a ORDER object. I want to pull all order objects for a certain USERID so something like getitems( USERID+'%', function()... would work good for my use case. |
It would be even more awesome to support MongoDB like queries. |
Is it possible to get a list of all keys currently stored? Something like keys(callback) implemented in lawnchair. Would be useful as a way of doing some housekeeping if the max size of the store was being reached. |
There's nothing like that yet, but I suppose it's also not a bad API to include. Did you want to take a crack at it? If you'd like to see it please file a separate issue (or send a pull request if you want to code it). |
For now I've created Issue 136. Thanks all for localForage! |
@thgreasi wrote in #291 an API I like for these multi-item calls: How about: Promise.all([
localforage.getItem('item1'),
localforage.getItem('item2')
]).then(function(results) {
console.log(results);
});
// OR
var items = ['item1', 'item2', 'item3'];
var promises = items.map(function(item) { return localforage.getItem(item); });
Promise.all(promises).then(function(results) {
console.log(results);
}); If getItems() / setItems() are going to be implemented by localforage at some point, then something like the 2nd example might actually have to be used by some drivers. |
If something like this was to be implemented, how the return object should look like?
[{
key:'test1',
value: 'value1'
}, {
key:'test2',
value: 'value2'
}]
{
'test1': 'value1',
'test2': 'value2'
} ??? For me: obj pros:
array pros:
|
To iterate over the results they can always use Object.keys, I think the second (object) one is nicer as it’s a basic return object that can be extended but is easy to grab items out of. Using the array the syntax is more annoying if you know exactly what you want. It would also mean we’d either need to guarantee order or you’d have to iterate through to get a key. Object for sure! -tofumatt On 10 May 2015 at 10:24:45, Thodoris Greasidis (notifications@github.com) wrote: If something like this was to be implemented, how the return object should look like? Array of KeyValues For me: It is more straightforward/efficient in retrieving a specific value. array pros |
@tofumatt I was just wandering if anyone could report any edge case or strange behavior when setting any special/reserved key as a property to an object. PS: I also like for..in with Object.hasOwnProperty to support pre-es5 browsers. Hope it has the same results. |
I can’t think of too many and I’d think it would crop up before saving to localForage though… it would be a problem in the data BEFORE we did a get/set. I think ^_^ -tofumatt On 10 May 2015 at 11:27:24, Thodoris Greasidis (notifications@github.com) wrote: @tofumatt I was just wandering if anyone could report any edge case or strange behavior when setting any special/reserved key as a property to an object. PS: I also like for..in with Object.hasOwnProperty to support pre-es5 browsers. Hope it has the same results. — |
FYI: Chrome is about to implement Firefox has already implemented the unprefixed |
Oh, that is awesome!
|
Can you give a try to thgreasi/localForage-getItems ? The jsperf testcases (found in README) gave me mixed results. The |
This is probably not the best place to discus it, but I have also been experimenting with a startsWith implementation. |
whats the status of this feature? |
It's not available yet, but we'll update the issue when it is. I'm not sure anyone is working on it right now. |
You can use the aforementioned plugin if you need it now. |
@tofumatt The plugin itself was structured in a way that would ease the creation of a PR. I could open one after the holidays if we want something like this as part of the main library. In order to reduce duplication, we could wire up the existing getItem method to use the composite version with a single item as a parameter. On the other hand setItems gave me much better performance gains than getItems. |
I do like the plugin way, I’m starting to feel like we can strike a balance on library size and features. For now I’d recommend using the plugin and I'll think about whether we want to merge this in directly. |
👍 on the plugins... that way we can push new experimental features |
Yes, it would be convenient. |
After doing some performance measurements on my app I notice I suffer a lot from doing this:
This is causing a lot of excess work for the browser if the list is long (e.g. 1,000+).
I know the localStorage spec doesn't have support
getItems()
but in most cases IndexDB is supported and it appears to have low level support for getting multiple keys which could hopefully reduce the overhead in total.For the localStorage fallback, this would be trivial to wrap up with a for loop of kinds.
The text was updated successfully, but these errors were encountered: