Giter Site home page Giter Site logo

Comments (28)

tofumatt avatar tofumatt commented on May 18, 2024 8

@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.

from localforage.

tamer1an avatar tamer1an commented on May 18, 2024 2

Yes, it would be convenient.
Please consider adding that feature. :godmode:

from localforage.

tofumatt avatar tofumatt commented on May 18, 2024 1

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.

from localforage.

peterbe avatar peterbe commented on May 18, 2024

For what it's worth, rather cryptically, memcache's get() takes multiple keys.
http://code.google.com/p/memcached/wiki/NewCommands#get

from localforage.

kyoshino avatar kyoshino commented on May 18, 2024

With IndexedDB, the undocumented IDBObjectStore.mozGetAll method (+ filtering) is much faster than iterating each items. I have used it in my app. This method is currently Gecko-specific but will be standardized and unprefixed.

from localforage.

fwenzel avatar fwenzel commented on May 18, 2024

fwiw, websql obviously also supports bulk get.

from localforage.

peterbe avatar peterbe commented on May 18, 2024

@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.

from localforage.

designbyadrian avatar designbyadrian commented on May 18, 2024

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?

from localforage.

tofumatt avatar tofumatt commented on May 18, 2024

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 getItems().

I think the queries would be overkill.

from localforage.

peterbe avatar peterbe commented on May 18, 2024

"Translating actual SQL queries"?? No, all I want is something like localForage.getItems(some array of keys, function(array of responses).
It would be moderately trivial to do my own fake wrapper but ultimately what I want is just one query to the database instead of one per every key I want to look up.

from localforage.

bbinckes avatar bbinckes commented on May 18, 2024

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.

from localforage.

magalhas avatar magalhas commented on May 18, 2024

It would be even more awesome to support MongoDB like queries.

from localforage.

dwhogg avatar dwhogg commented on May 18, 2024

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.

from localforage.

tofumatt avatar tofumatt commented on May 18, 2024

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).

from localforage.

dwhogg avatar dwhogg commented on May 18, 2024

For now I've created Issue 136. Thanks all for localForage!

from localforage.

thgreasi avatar thgreasi commented on May 18, 2024

If something like this was to be implemented, how the return object should look like?

  • Array of KeyValues
[{
  key:'test1',
  value: 'value1'
}, {
  key:'test2',
  value: 'value2'
}]
  • or just an object like
{
  'test1': 'value1',
  'test2': 'value2'
}

???
What's most preferable of the two in your opinion?
What are the pros and cons in each case in your opinion?

For me:
+1 for obj result

obj pros:

  • It is more straightforward/efficient in retrieving a specific value.

array pros:

  • Someone might argue that the array is more convenient for iterating over the results.

from localforage.

tofumatt avatar tofumatt commented on May 18, 2024

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 ([email protected]) wrote:

If something like this was to be implemented, how the return object should look like?

Array of KeyValues
[{
key:'test1',
value: 'value1'
}, {
key:'test2',
value: 'value2'
}]
or just an object like
{
'test1': 'value1',
'test2': 'value2'
}
???
What's most preferable of the two in your opinion?
What are the pros and cons in each case in your opinion?

For me:
+1 for obj result
obj pros:

It is more straightforward/efficient in retrieving a specific value. array pros
Someone might argue that the array is more convenient for iterating over the results.

Reply to this email directly or view it on GitHub.

from localforage.

thgreasi avatar thgreasi commented on May 18, 2024

@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.

from localforage.

tofumatt avatar tofumatt commented on May 18, 2024

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 ([email protected]) 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.


Reply to this email directly or view it on GitHub.

from localforage.

kyoshino avatar kyoshino commented on May 18, 2024

FYI:

Chrome is about to implement IDBObjectStore.getAll.
https://code.google.com/p/chromium/issues/detail?id=457450

Firefox has already implemented the unprefixed getAll method, but it's still behind a pref. mozGetAll is not documented on MDN but available by default.
https://bugzilla.mozilla.org/show_bug.cgi?id=920633

from localforage.

tofumatt avatar tofumatt commented on May 18, 2024

from localforage.

thgreasi avatar thgreasi commented on May 18, 2024

Can you give a try to thgreasi/localForage-getItems ?
I thought it would be better for developing and reviewing if it was written (initially, until merged) as an extension library for localforage.

The jsperf testcases (found in README) gave me mixed results.
For big enough number of requested keys the gains are pretty good.
For small number of requested keys, chrome does a pretty god job parallelizing the independent read-only requests. As a result the generic method is sometimes faster.

The generic method is based on the code described above and it should be the default implementation for any driver that can't offer a better (driver specific) implementation (eg localstorage).

from localforage.

thgreasi avatar thgreasi commented on May 18, 2024

This is probably not the best place to discus it, but I have also been experimenting with a startsWith implementation.

from localforage.

siddo420 avatar siddo420 commented on May 18, 2024

whats the status of this feature?

from localforage.

tofumatt avatar tofumatt commented on May 18, 2024

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.

from localforage.

thgreasi avatar thgreasi commented on May 18, 2024

You can use the aforementioned plugin if you need it now.

from localforage.

thgreasi avatar thgreasi commented on May 18, 2024

@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.
It seems that doing concurrent getItem requests and composing them with Promise.all() works faster than fetching the items in a single transaction when there is no one else writing on the db at the same time. See next comment.

from localforage.

thgreasi avatar thgreasi commented on May 18, 2024

👍 on the plugins... that way we can push new experimental features
As a side note & correction on my earlier performance related comments,
I just had a rerun of the jsperf benchmarks and it seems that the current versions of Firefox (v44) and Chrome (v47) give better result on getItems() than multiple generic concurent getItem() calls.

from localforage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.