-
Notifications
You must be signed in to change notification settings - Fork 22.9k
Technical review: Add docs for getAllRecords() and direction option #41398
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
base: main
Are you sure you want to change the base?
Technical review: Add docs for getAllRecords() and direction option #41398
Conversation
Hi @SteveBeckerMSFT! I created this PR to document the new IDB |
Absolutely. Thanks for writing this documentation. I'll review soon. |
- : See the earlier [`query`](#query) definition. | ||
- `count` {{optional_inline}} | ||
- : See the earlier [`count`](#count) definition. | ||
- `direction` {{optional_inline}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI -- this is the same parameter used by IDBCursor, which has existing documentation here:
https://developer.mozilla.org/en-US/docs/Web/API/IDBCursor/direction#value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. I've updated the new sections to be a bit more consistent with the wording used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this! Left a few comments. Please let me know if you have any questions.
- : The objects are traversed from the beginning, in increasing key order. In cases where keys are duplicated across multiple objects, only the first encountered object with each key is retrieved. | ||
- `prev` | ||
- : The objects are traversed from the end, in decreasing key order. | ||
- `prevunique` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- One potential gotcha with 'prevunique' is that the record selected is the first encountered record in the forward direction. It looks like the cursor definition above might also need an update. For example, say we have the database:
key1, value1
key1, value2
key1, value3
key2, value4
key3, value5
key4, value6,
key4, value7
prevunique
would return the exact opposite of nextunique
, which is:
[{key4, value6}, {key3, value5}, {key2, value5}, {key1, value1}]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so it is "record closest to the start" for each duplicated key in the case of both nextunique
and prevunique
. I've updated all the pages to correct this, including the IDBCursor.direction
page.
- : An enumerated value specifying the direction in which the records are traversed, which in turn defines the order in which they are returned. Possible values are: | ||
- `next` | ||
- : The records are traversed from the beginning, in increasing key order. This is the default value. | ||
- `nextunique` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For IDBObjectStore, 'next' & 'nextunique' must return the same values because duplicate keys are not allowed. IDBIndex allows duplicate keys when created with the option unique=false.
https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex#unique
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've updated the *unique
descriptions in the IDBObjectStore.*
pages to account for this.
|
||
If the operation is successful, the value of the request's {{domxref("IDBRequest.result", "result")}} property is an {{jsxref("Array")}} of objects representing all the records matching the given query, up to the value of `count`, if `count` was supplied. | ||
|
||
Each object contains the following properties: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resulting array contains IDBRecord
objects:
interface IDBRecord {
readonly attribute any key;
readonly attribute any primaryKey;
readonly attribute any value;
};
https://www.w3.org/TR/IndexedDB/#record-interface
This includes a key property. For IDBObjectStore, the key and primaryKey are the same. For IDBIndex, the key is the index key for the record.
This is the same as IDBCursorWithValue, which also has the value, key and primaryKey properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, OK, I misunderstood this a bit. I've updated the description as appropriate on each getAllRecords()
page.
|
||
- `DataError` {{domxref("DOMException")}} | ||
- : Thrown if: | ||
- The specified [`query`](#query) parameter is invalid, has an invalid type, or doesn't exist in the index. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" or doesn't exist in the index."
Since this is for IDBObjectStore, the indexes are not checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's needed for getAllRecordS() in IDBIndex either. Empty queries return no results. They do not throw exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK; I've removed that exception description on both pages.
Preview URLs (9 pages)
External URLs (3)URL:
URL:
URL:
|
I assume you are going to eventually add |
Description
Chromium 141 adds support for the following features in
IDBIndex
andIDBObjectStore
:getAllRecords()
method.direction
option in thegetAll()
andgetAllKeys()
methods.See https://chromestatus.com/feature/5124331450138624, and also see https://patrickbrosset.com/articles/2024-11-19-even-faster-indexeddb-reads-with-getallrecords/ for the context behind the additions.
This PR adds reference content covering the above features. You can test
getAllRecords()
using @captainbrosset's demo at https://microsoftedge.github.io/Demos/idb-getallrecords/.Motivation
Additional details
Related issues and pull requests