Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. IDBObjectStore
  4. getAllRecords()

IDBObjectStore: getAllRecords() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

ThegetAllRecords() method of theIDBObjectStoreinterface retrieves all records (including primary keys and values) from the object store.

getAllRecords() effectively combines the functionality ofgetAllKeys() andgetAll() 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

js
getAllRecords()getAllRecords(options)

Parameters

An options object whose properties can include:

queryOptional

A key or anIDBKeyRange identifying the records to retrieve. If this value isnull or not specified, the browser will use an unbound key range.

countOptional

The number of records to return. If this value exceeds the number of records in the query, the browser will retrieve only the queried records. If the value is less than0 or greater than2^32 - 1, aTypeError exception will be thrown.

directionOptional

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

The records are traversed from the beginning, in increasing key order. This will yield the same records asnext, because duplicate keys are not allowed inIDBObjectStores.

prev

The records are traversed from the end, in decreasing key order.

prevunique

The records are traversed from the end, in decreasing key order. This will yield the same records asprev, because duplicate keys are not allowed inIDBObjectStores.

Return value

AnIDBRequest object on which subsequent events related to this operation are fired.

If the operation is successful, the value of the request'sresult property is anarray of objects representing all records that match the given query, up to the number specified bycount (if provided).

Each object contains the following properties:

key

A value representing the record's key.

primaryKey

The record's key; identical to thekey property.

value

A value representing the record's value.

Exceptions

This method may raise aDOMException of the following types:

InvalidStateErrorDOMException

Thrown if theIDBObjectStore has been deleted or removed.

TransactionInactiveErrorDOMException

Thrown if thisIDBObjectStore's transaction is inactive.

TypeErrorDOMException

Thrown if thecount parameter is not between0 and2^32 - 1, inclusive.

Examples

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("Records successfully retrieved");});

Specifications

Specification
Indexed Database API 3.0
# dom-idbobjectstore-getallrecords

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp