-
Notifications
You must be signed in to change notification settings - Fork 23.2k
Ff153 Add IDBRecord #44540
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
Open
hamishwillee
wants to merge
2
commits into
mdn:main
Choose a base branch
from
hamishwillee:ff153idbrecord
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−28
Open
Ff153 Add IDBRecord #44540
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/)). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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
keyfield.