-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add descending order for getAll() and getAllKeys() #130
Comments
Just talked with @aliams, and his suggestion was to instead do something like: objectStore.getAllKeysFromEnd(keyRange, batchSize).onsuccess = ...
objectStore.getAllFromEnd(keyRange, batchSize).onsuccess = ... This would be feature-detectable, although it's maybe not as elegant as an Iterable or generator or some other fancier alternative. |
@inexorabletash, thoughts on this? |
Seems plausible. I'm don't like the ever-growing list of methods as we add query types one by one and thus need to make them feature detectable, but we haven't come up with a good pattern for feature detecting options. (Or maybe we have and I just don't know?) Crazy thoughts like Is this a hint that Edge might be implementing here? :) |
We thought the same in terms of an ever-growing list of methods. However, we were thinking maybe this was analogous to having indexOf() and lastIndexOf(). @nolanlawson brought up how he would like to be able to efficiently iterate through an object store backwards in PouchDB since currently they're using a cursor for backwards iteration and getAll for forward iteration (if available). He brought up that he raised the issue here and I just wanted to help give it some attention in case we want to define this for v3 of the IDB spec. In terms of implementing such a method, I would support it since it would be helpful for use cases such as the one @nolanlawson mentioned :) |
It's sad that since this is not in the initial spec, future versions need feature detection. Is there any other way forward? Example 1: Example 2: |
Example 2 will not throw; extra arguments are ignored. (JS built-in method semantics, which WebIDL-based methods inherit) |
Would having an explicit features object, ie no implicit detection, be a bad idea? |
There hasn't been a proposal that would apply to all specs that people are happy with. Feature detection is possible here using a getter on the passed dictionary. Not pretty but it works. |
Thanks, looks like it will be a lot of work, best of luck |
TPAC 2019 Web Apps Indexed DB triage notes:
We'll try to come up with a holistic proposal. |
Работает плохо. Вынужденно загружает вообще всю историю просмотров, чтобы получить несколько последних элементов, как как нативные возможности idb не позволяют получить N записей по индексу с конца. Смотри: jakearchibald/idb#176 w3c/IndexedDB#130
Работает не лучшим образом. Вынужденно загружает вообще всю историю просмотров, чтобы получить несколько последних элементов, как как нативные возможности idb не позволяют получить N записей по индексу с конца. Смотри: jakearchibald/idb#176 w3c/IndexedDB#130
use Curser prev prevUnique I think this work for now |
How about using a negativ limit to indicate "backwards", changing the "count" type from "unsigned long" to "long"? No limit could be expressed by -Infinity, assuming this would be clamped to the minimum long value? |
TPAC 2024: The getAllEntries() proposal adds a direction option to support reverse iteration. For consistency, should we also expose this option to getAll() and getAllKeys()? Providing the direction option on getAllKeys() might be useful for reverse iteration scenarios that don't want to load every value enumerated like getAllEntries() behaves. |
In PouchDB we're implementing a "batched cursor" using
getAll()
andgetAllKeys()
(pouchdb/pouchdb#6060, pouchdb/pouchdb#6031). E.g. it can be used to paginate through an objectStoren
records at a time, given a lower bound and optional upper bound.Unfortunately we are only able to do this in ascending order, since in descending order the
limit
will always give us the firstn
records instead of the lastn
records. it would be nice if we could do something like:... where the
batchSize
would fetch the highestn
records instead of the lowest. The downside of this method is that it's tricky to feature-detect unless you insert some dummy data and then try to fetch it, although maybe there's a more clever way.The text was updated successfully, but these errors were encountered: