From 8d7c45db6a56acb0f2a9c4065900511da46adfce Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Mon, 22 Jun 2026 14:59:09 +1000 Subject: [PATCH 1/2] FF153 IDBRecord added --- .../web/api/idbindex/getallrecords/index.md | 6 +- .../api/idbobjectstore/getallrecords/index.md | 13 ++-- files/en-us/web/api/idbrecord/index.md | 61 +++++++++++++++++++ files/en-us/web/api/idbrequest/index.md | 25 +++++--- .../en-us/web/api/idbrequest/result/index.md | 20 +++--- files/jsondata/GroupData.json | 1 + 6 files changed, 98 insertions(+), 28 deletions(-) create mode 100644 files/en-us/web/api/idbrecord/index.md diff --git a/files/en-us/web/api/idbindex/getallrecords/index.md b/files/en-us/web/api/idbindex/getallrecords/index.md index 7200a4b8e1a0f56..0d46d1588004793 100644 --- a/files/en-us/web/api/idbindex/getallrecords/index.md +++ b/files/en-us/web/api/idbindex/getallrecords/index.md @@ -45,12 +45,12 @@ An options object whose properties can include: An {{domxref("IDBRequest")}} object on which subsequent events related to this operation are fired. -If the operation is successful, the value of the request's {{domxref("IDBRequest.result", "result")}} property is an {{jsxref("Array", "array")}} of objects representing all the records that match the given query, up to the number specified by `count` (if provided). +If the operation is successful, the value of the request's {{domxref("IDBRequest.result", "result")}} property is an {{jsxref("Array", "array")}} of {{domxref("IDBRecord")}} instances representing all the records that match the given query, up to the number specified by `count` (if provided). -Each object contains the following properties: +Each {{domxref("IDBRecord")}} instance contains the following properties: - `key` - - : A value representing the record's key. + - : A value representing the record's key in the index. - `primaryKey` - : A value representing the key of the record in the index's associated {{domxref("IDBObjectStore")}}. - `value` diff --git a/files/en-us/web/api/idbobjectstore/getallrecords/index.md b/files/en-us/web/api/idbobjectstore/getallrecords/index.md index 2b3f68965982c6e..0ccf1917a2a764b 100644 --- a/files/en-us/web/api/idbobjectstore/getallrecords/index.md +++ b/files/en-us/web/api/idbobjectstore/getallrecords/index.md @@ -10,10 +10,10 @@ browser-compat: api.IDBObjectStore.getAllRecords {{ APIRef("IndexedDB") }}{{SeeCompatTable}} -The **`getAllRecords()`** method of the {{domxref("IDBObjectStore")}} -interface retrieves all records (including primary keys and values) from the object store. +The **`getAllRecords()`** method of the {{domxref("IDBObjectStore")}} interface retrieves all records (including primary keys and values) from the object store. -`getAllRecords()` effectively combines the functionality of {{domxref("IDBObjectStore.getAllKeys", "getAllKeys()")}} and {{domxref("IDBObjectStore.getAll", "getAll()")}} by enumerating both primary keys and values at the same time. This combined operation enables certain data retrieval patterns to be significantly faster than alternatives such as iteration with cursors. +`getAllRecords()` effectively combines the functionality of {{domxref("IDBObjectStore.getAllKeys", "getAllKeys()")}} and {{domxref("IDBObjectStore.getAll", "getAll()")}} by enumerating both primary keys and values at the same time. +This combined operation enables certain data retrieval patterns to be significantly faster than alternatives such as iteration with cursors. ## Syntax @@ -45,14 +45,15 @@ An options object whose properties can include: An {{domxref("IDBRequest")}} object on which subsequent events related to this operation are fired. -If the operation is successful, the value of the request's {{domxref("IDBRequest.result", "result")}} property is an {{jsxref("Array", "array")}} of objects representing all records that match the given query, up to the number specified by `count` (if provided). +If the operation is successful, the value of the request's {{domxref("IDBRequest.result", "result")}} property is an {{jsxref("Array", "array")}} of {{domxref("IDBRecord")}} instances representing all records that match the given query, up to the number specified by `count` (if provided). -Each object contains the following properties: +Each {{domxref("IDBRecord")}} instance contains the following properties: - `key` - : A value representing the record's key. + This is identical to the `primaryKey` property. - `primaryKey` - - : The record's key; identical to the `key` property. + - : The record's primary key - `value` - : A value representing the record's value. diff --git a/files/en-us/web/api/idbrecord/index.md b/files/en-us/web/api/idbrecord/index.md new file mode 100644 index 000000000000000..290306fd60e96b2 --- /dev/null +++ b/files/en-us/web/api/idbrecord/index.md @@ -0,0 +1,61 @@ +--- +title: IDBRecord +slug: Web/API/IDBRecord +page-type: web-api-interface +browser-compat: api.IDBRecord +--- + +{{APIRef("IndexedDB")}} {{AvailableInWorkers}} + +The **`IDBRecord`** interface of the [IndexedDB API](/en-US/docs/Web/API/IndexedDB_API) represents a snapshot of a single record in an {{domxref("IDBObjectStore")}} or {{domxref("IDBIndex")}}. + +A request for records using {{domxref("IDBObjectStore.getAllRecords()")}} or {{domxref("IDBIndex.getAllRecords()")}} returns a {{domxref("IDBRequest")}} instance. +On success the returned object's {{domxref("IDBRequest.result", "result")}} method is populated with an array of `IDBRecord` instances. + +## Instance properties + +- `key` {{ReadOnlyInline}} + - : A value representing the record's key. + For an object store record this will be the same as `primaryKey`. + For an index record it will be the record's key within the index. +- `primaryKey` {{ReadOnlyInline}} + - : A value representing the key of the record in the index's associated {{domxref("IDBObjectStore")}}. +- `value` {{ReadOnlyInline}} + - : A value representing the record's value. + +## Instance methods + +_None._ + +## Example + +In the following code snippet, we open a database asynchronously and make a request; `onerror` and `onsuccess` functions are included to handle the success and error cases. +For a full working example, see our [To-do Notifications](https://github.com/mdn/dom-examples/tree/main/to-do-notifications) app ([view example live](https://mdn.github.io/dom-examples/to-do-notifications/).) + +```js +const query = IDBKeyRange.lowerBound("myKey", true); +const objectStore = transaction.objectStore("contactsList"); + +const myRecords = (objectStore.getAllRecords({ + query, + count: "100", + direction: "prev", +}).onsuccess = (event) => { + console.log(myRecords.result); // Array of IDBRecord instances +}); +``` + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{domxref("IDBObjectStore.getAllRecords()")}} +- {{domxref("IDBIndex.getAllRecords()")}} +- [Using IndexedDB](/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB) +- Reference example: [To-do Notifications](https://github.com/mdn/dom-examples/tree/main/to-do-notifications) ([View the example live](https://mdn.github.io/dom-examples/to-do-notifications/)). diff --git a/files/en-us/web/api/idbrequest/index.md b/files/en-us/web/api/idbrequest/index.md index 8fce1ce451311af..1fe0dbc3a45d0d7 100644 --- a/files/en-us/web/api/idbrequest/index.md +++ b/files/en-us/web/api/idbrequest/index.md @@ -7,15 +7,7 @@ browser-compat: api.IDBRequest {{APIRef("IndexedDB")}} {{AvailableInWorkers}} -The **`IDBRequest`** interface of the IndexedDB API provides access to results of asynchronous requests to databases and database objects using event handler attributes. Each reading and writing operation on a database is done using a request. - -The request object does not initially contain any information about the result of the operation, but once information becomes available, an event is fired on the request, and the information becomes available through the properties of the `IDBRequest` instance. - -All asynchronous operations immediately return an `IDBRequest` instance. Each request has a `readyState` that is set to the `'pending'` state; this changes to `'done'` when the request is completed or fails. When the state is set to `done`, every request returns a `result` and an `error`, and an event is fired on the request. When the state is still `pending`, any attempt to access the `result` or `error` raises an `InvalidStateError` exception. - -In plain words, all asynchronous methods return a request object. If the request has been completed successfully, the result is made available through the `result` property and an event indicating success is fired at the request ({{domxref("IDBRequest.success_event", "success")}}). If an error occurs while performing the operation, the exception is made available through the `error` property and an error event is fired ({{domxref("IDBRequest.error_event", "error")}}). - -The interface {{domxref("IDBOpenDBRequest")}} is derived from `IDBRequest`. +The **`IDBRequest`** interface of the IndexedDB API provides access to results of asynchronous requests to databases and database objects using event handler attributes. {{InheritanceDiagram}} @@ -47,8 +39,23 @@ Listen to these events using `addEventListener()` or by assigning an event liste - [`success`](/en-US/docs/Web/API/IDBRequest/success_event) - : Fired when an `IDBRequest` succeeds. +## Description + +The results of all database read and write operations are reported using a request object of this type. + +The request object does not initially contain any information about the result of the operation, but once information becomes available, an event is fired on the request, and the information becomes available through the properties of the `IDBRequest` instance. + +All asynchronous operations immediately return an `IDBRequest` instance. Each request has a `readyState` that is set to the `'pending'` state; this changes to `'done'` when the request is completed or fails. When the state is set to `done`, every request returns a `result` and an `error`, and an event is fired on the request. When the state is still `pending`, any attempt to access the `result` or `error` raises an `InvalidStateError` exception. + +In plain words, all asynchronous methods return a request object. If the request has been completed successfully, the result is made available through the `result` property and an event indicating success is fired at the request ({{domxref("IDBRequest.success_event", "success")}}). If an error occurs while performing the operation, the exception is made available through the `error` property and an error event is fired ({{domxref("IDBRequest.error_event", "error")}}). +The data in `result` depends on the operation that was called. + +The interface {{domxref("IDBOpenDBRequest")}} is derived from `IDBRequest`. + ## Example +### Basic usage + In the following code snippet, we open a database asynchronously and make a request; `onerror` and `onsuccess` functions are included to handle the success and error cases. For a full working example, see our [To-do Notifications](https://github.com/mdn/dom-examples/tree/main/to-do-notifications) app ([view example live](https://mdn.github.io/dom-examples/to-do-notifications/).) ```js diff --git a/files/en-us/web/api/idbrequest/result/index.md b/files/en-us/web/api/idbrequest/result/index.md index b35e839940de838..b5b2ebbe3f3fc3d 100644 --- a/files/en-us/web/api/idbrequest/result/index.md +++ b/files/en-us/web/api/idbrequest/result/index.md @@ -8,26 +8,26 @@ browser-compat: api.IDBRequest.result {{ APIRef("IndexedDB") }} {{AvailableInWorkers}} -The **`result`** read-only property of the -{{domxref("IDBRequest")}} interface returns the result of the request. +The **`result`** read-only property of the {{domxref("IDBRequest")}} interface returns the result of the request. + +The value depends on the request that was made. +For example, the {{domxref("IDBObjectStore.getAllRecords()")}} and {{domxref("IDBIndex.getAllRecords()")}} methods populate this property with an array of {{domxref("IDBRecord")}} instances on successful completion of the request. ## Value -any +any. ### Exceptions - `InvalidStateError` {{domxref("DOMException")}} - - : Thrown when attempting to access the property if the request - is not completed, and therefore the result is not available. + - : Thrown when attempting to access the property if the request is not completed, and therefore the result is not available. ## Examples -The following example requests a given record title, `onsuccess` gets the -associated record from the {{domxref("IDBObjectStore")}} (made available -as `objectStoreTitleRequest.result`), updates -one property of the record, and then puts the updated record back into the object -store. For a full working example, see our [To-do Notifications](https://github.com/mdn/dom-examples/tree/main/to-do-notifications) app ([View the example live](https://mdn.github.io/dom-examples/to-do-notifications/)). +### Basic usage + +The following example requests a given record title, `onsuccess` gets the associated record from the {{domxref("IDBObjectStore")}} (made available as `objectStoreTitleRequest.result`), updates one property of the record, and then puts the updated record back into the object store. +For a full working example, see our [To-do Notifications](https://github.com/mdn/dom-examples/tree/main/to-do-notifications) app ([View the example live](https://mdn.github.io/dom-examples/to-do-notifications/)). ```js const title = "Walk dog"; diff --git a/files/jsondata/GroupData.json b/files/jsondata/GroupData.json index 268a604915cbd4c..93e3f79248c1bf1 100644 --- a/files/jsondata/GroupData.json +++ b/files/jsondata/GroupData.json @@ -988,6 +988,7 @@ "IDBKeyRange", "IDBObjectStore", "IDBOpenDBRequest", + "IDBRecord", "IDBRequest", "IDBTransaction", "IDBVersionChangeEvent" From dcedfc69f88d165aed0e4c5a172ef469bdd786c2 Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Mon, 22 Jun 2026 15:03:04 +1000 Subject: [PATCH 2/2] typos --- files/en-us/web/api/idbobjectstore/getallrecords/index.md | 2 +- files/en-us/web/api/idbrecord/index.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/files/en-us/web/api/idbobjectstore/getallrecords/index.md b/files/en-us/web/api/idbobjectstore/getallrecords/index.md index 0ccf1917a2a764b..34362890754dbb9 100644 --- a/files/en-us/web/api/idbobjectstore/getallrecords/index.md +++ b/files/en-us/web/api/idbobjectstore/getallrecords/index.md @@ -53,7 +53,7 @@ Each {{domxref("IDBRecord")}} instance contains the following properties: - : A value representing the record's key. This is identical to the `primaryKey` property. - `primaryKey` - - : The record's primary key + - : The record's primary key. - `value` - : A value representing the record's value. diff --git a/files/en-us/web/api/idbrecord/index.md b/files/en-us/web/api/idbrecord/index.md index 290306fd60e96b2..15fe105d3781e0c 100644 --- a/files/en-us/web/api/idbrecord/index.md +++ b/files/en-us/web/api/idbrecord/index.md @@ -9,8 +9,8 @@ browser-compat: api.IDBRecord The **`IDBRecord`** interface of the [IndexedDB API](/en-US/docs/Web/API/IndexedDB_API) represents a snapshot of a single record in an {{domxref("IDBObjectStore")}} or {{domxref("IDBIndex")}}. -A request for records using {{domxref("IDBObjectStore.getAllRecords()")}} or {{domxref("IDBIndex.getAllRecords()")}} returns a {{domxref("IDBRequest")}} instance. -On success the returned object's {{domxref("IDBRequest.result", "result")}} method is populated with an array of `IDBRecord` instances. +A request for records using {{domxref("IDBObjectStore.getAllRecords()")}} or {{domxref("IDBIndex.getAllRecords()")}} returns an {{domxref("IDBRequest")}} instance. +On success the returned object's {{domxref("IDBRequest.result", "result")}} property is populated with an array of `IDBRecord` instances. ## Instance properties