Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions files/en-us/web/api/idbindex/getallrecords/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I was going to remove the property values below and in the corresponding store method.
However it is useful to list them because in the object strore case they are the same - the store ONLY has the primary key, so this is duplicated in the key field.


- `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`
Expand Down
13 changes: 7 additions & 6 deletions files/en-us/web/api/idbobjectstore/getallrecords/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down
61 changes: 61 additions & 0 deletions files/en-us/web/api/idbrecord/index.md
Original file line number Diff line number Diff line change
@@ -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 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

- `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/)).
25 changes: 16 additions & 9 deletions files/en-us/web/api/idbrequest/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions files/en-us/web/api/idbrequest/result/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +13 to +14

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI If I ever have to do more work here, my intent is to build out this as a list for the different types.


## 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";
Expand Down
1 change: 1 addition & 0 deletions files/jsondata/GroupData.json
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@
"IDBKeyRange",
"IDBObjectStore",
"IDBOpenDBRequest",
"IDBRecord",
"IDBRequest",
"IDBTransaction",
"IDBVersionChangeEvent"
Expand Down