Skip to content

Conversation

chrisdavidmills
Copy link
Contributor

Description

Chromium 141 adds support for the following features in IDBIndex and IDBObjectStore:

  1. The new getAllRecords() method.
  2. The direction option in the getAll() and getAllKeys() 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

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner October 5, 2025 16:31
@chrisdavidmills chrisdavidmills requested review from wbamberg and removed request for a team October 5, 2025 16:31
@github-actions github-actions bot added Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Oct 5, 2025
@chrisdavidmills chrisdavidmills changed the title Add docs for getAllRecords() and direction option Oct 5, 2025
@chrisdavidmills
Copy link
Contributor Author

Hi @SteveBeckerMSFT! I created this PR to document the new IDB getAllRecords() method and direction option. @captainbrosset says you would be a good person to tech review it. Are you OK to do that? Thanks in advance.

@SteveBeckerMSFT
Copy link

Are you OK to do that?

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}}

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

Copy link
Contributor Author

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.

Copy link

@SteveBeckerMSFT SteveBeckerMSFT left a 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`

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}]

Copy link
Contributor Author

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`

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

Copy link
Contributor Author

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:

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.

Copy link
Contributor Author

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.

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.

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.

Copy link
Contributor Author

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.

@Josh-Cena
Copy link
Member

I assume you are going to eventually add IDBRecord and member pages? This is a real interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed

3 participants