4.5. The IDBObjectStore interface

The [IDBObjectStore](#idbobjectstore) interface represents an object store handle.

  1. [Exposed=(Window,Worker)]
  2. interface IDBObjectStore {
  3. attribute DOMString name;
  4. readonly attribute any keyPath;
  5. readonly attribute DOMStringList indexNames;
  6. [SameObject] readonly attribute IDBTransaction transaction;
  7. readonly attribute boolean autoIncrement;
  8.  
  9. [NewObject] IDBRequest put(any value, optional any key);
  10. [NewObject] IDBRequest add(any value, optional any key);
  11. [NewObject] IDBRequest delete(any query);
  12. [NewObject] IDBRequest clear();
  13. [NewObject] IDBRequest get(any query);
  14. [NewObject] IDBRequest getKey(any query);
  15. [NewObject] IDBRequest getAll(optional any query,
  16. optional [EnforceRange] unsigned long count);
  17. [NewObject] IDBRequest getAllKeys(optional any query,
  18. optional [EnforceRange] unsigned long count);
  19. [NewObject] IDBRequest count(optional any query);
  20.  
  21. [NewObject] IDBRequest openCursor(optional any query,
  22. optional IDBCursorDirection direction = "next");
  23. [NewObject] IDBRequest openKeyCursor(optional any query,
  24. optional IDBCursorDirection direction = "next");
  25.  
  26. IDBIndex index(DOMString name);
  27.  
  28. [NewObject] IDBIndex createIndex(DOMString name,
  29. (DOMString or sequence<DOMString>) keyPath,
  30. optional IDBIndexParameters options);
  31. void deleteIndex(DOMString name);
  32. };
  33.  
  34. dictionary IDBIndexParameters {
  35. boolean unique = false;
  36. boolean multiEntry = false;
  37. };

store . [name](#dom-idbobjectstore-name)

Returns the name of the store.

store . [name](#dom-idbobjectstore-name) = newName

Updates the name of the store to newName.

Throws “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) if not called within an upgrade transaction.

store . [keyPath](#dom-idbobjectstore-keypath)

Returns the key path of the store, or null if none.

list . [indexNames](#dom-idbobjectstore-indexnames)

Returns a list of the names of indexes in the store.

store . [transaction](#dom-idbobjectstore-transaction)

Returns the associated transaction.

store . [autoIncrement](#dom-idbobjectstore-autoincrement)

Returns true if the store has a key generator, and false otherwise.

The name attribute’s getter must return this object store handle‘s name.

Is this the same as the object store‘s name? As long as the transaction has not finished, this is the same as the associated object store‘s name. But once the transaction has finished, this attribute will not reflect changes made with a later upgrade transaction.

The [name](#dom-idbobjectstore-name) attribute’s setter must run these steps:

  1. Let name be the given value.

  2. Let transaction be this object store handle‘s transaction.

  3. Let store be this object store handle‘s object store.

  4. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. If transaction is not an upgrade transaction, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  6. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  7. If store’s name is equal to name, terminate these steps.

  8. If an object store named name already exists in store’s database, throw a “[ConstraintError](https://www.w3.org/TR/WebIDL-1/#constrainterror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  9. Set store’s name to name.

  10. Set this object store handle‘s name to name.

🚧 The [name](#dom-idbobjectstore-name) attribute’s setter is new in this edition. It is supported in Chrome 58, Firefox 51, and Safari 10.1. 🚧

The keyPath attribute’s getter must return this object store handle‘s object store‘s key path, or null if none. The key path is converted as a [DOMString](https://www.w3.org/TR/WebIDL-1/#idl-DOMString) (if a string) or a sequence (if a list of strings), per [WEBIDL].

The returned value is not the same instance that was used when the object store was created. However, if this attribute returns an object (specifically an Array), it returns the same object instance every time it is inspected. Changing the properties of the object has no effect on the object store.

The indexNames attribute’s getter must return a [DOMStringList](https://www.w3.org/TR/html52/single-page.html#domstringlist) associated with a sorted name list of the names of indexes in this object store handle‘s index set.

Is this the same as object store‘s list of index names? As long as the transaction has not finished, this is the same as the associated object store‘s list of index names. But once the transaction has finished, this attribute will not reflect changes made with a later upgrade transaction.

The transaction attribute’s getter must return this object store handle‘s transaction.

The autoIncrement attribute’s getter must return true if this object store handle‘s object store has a key generator, and false otherwise.

The following methods throw a “[ReadOnlyError](https://www.w3.org/TR/WebIDL-1/#readonlyerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) if called within a read-only transaction, and a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) if called when the transaction is not active.

request = store . [put](#dom-idbobjectstore-put)(value [, key])

request = store . [add](#dom-idbobjectstore-add)(value [, key])

Adds or updates a record in store with the given value and key.

If the store uses in-line keys and key is specified a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) will be thrown.

If [put()](#dom-idbobjectstore-put) is used, any existing record with the key will be replaced. If [add()](#dom-idbobjectstore-add) is used, and if a record with the key already exists the request will fail, with request’s [error](#dom-idbrequest-error) set to a “[ConstraintError](https://www.w3.org/TR/WebIDL-1/#constrainterror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

If successful, request’s [result](#dom-idbrequest-result) will be the record‘s key.

request = store . [delete](#dom-idbobjectstore-delete)(query)

Deletes records in store with the given key or in the given key range in query.

If successful, request’s [result](#dom-idbrequest-result) will be undefined.

request = store . [clear](#dom-idbobjectstore-clear)()

Deletes all records in store.

If successful, request’s [result](#dom-idbrequest-result) will be undefined.

The put(value, key) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. If transaction is a read-only transaction, throw a “[ReadOnlyError](https://www.w3.org/TR/WebIDL-1/#readonlyerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  6. If store uses in-line keys and key was given, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  7. If store uses out-of-line keys and has no key generator and key was not given, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  8. If key was given, then:

    1. Let r be the result of running the steps to convert a value to a key with key. Rethrow any exceptions.

    2. If r is invalid, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

    3. Let key be r.

  9. Let targetRealm be a user-agent defined Realm.

  10. Let clone be a clone of value in targetRealm. Rethrow any exceptions.

    Why create a copy of the value? The value is be serialized when stored. Treating it as a copy here allows other algorithms in this specification to treat it as an ECMAScript value, but implementations can optimize this if the difference in behavior is not observable.

  11. If store uses in-line keys, then:

    1. Let kpk be the result of running the steps to extract a key from a value using a key path with clone and store’s key path. Rethrow any exceptions.

    2. If kpk is invalid, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

    3. If kpk is not failure, let key be kpk.

    4. Otherwise (kpk is failure):

      1. If store does not have a key generator, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

      2. Otherwise, if the steps to check that a key could be injected into a value with clone and store’s key path return false, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  12. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to store a record into an object store as operation, using store, the clone as value, key, and with the no-overwrite flag unset.

The add(value, key) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. If transaction is a read-only transaction, throw a “[ReadOnlyError](https://www.w3.org/TR/WebIDL-1/#readonlyerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  6. If store uses in-line keys and key was given, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  7. If store uses out-of-line keys and has no key generator and key was not given, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  8. If key was given, then:

    1. Let r be the result of running the steps to convert a value to a key with key. Rethrow any exceptions.

    2. If r is invalid, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

    3. Let key be r.

  9. Let targetRealm be a user-agent defined Realm.

  10. Let clone be a clone of value in targetRealm. Rethrow any exceptions.

    Why create a copy of the value? The value is serialized when stored. Treating it as a copy here allows other algorithms in this specification to treat it as an ECMAScript value, but implementations can optimize this if the difference in behavior is not observable.

  11. If store uses in-line keys, then:

    1. Let kpk be the result of running the steps to extract a key from a value using a key path with clone and store’s key path. Rethrow any exceptions.

    2. If kpk is invalid, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

    3. If kpk is not failure, let key be kpk.

    4. Otherwise (kpk is failure):

      1. If store does not have a key generator, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

      2. Otherwise, if the steps to check that a key could be injected into a value with clone and store’s key path return false, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  12. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to store a record into an object store as operation, using store, clone as value, key, and with the no-overwrite flag set.

The delete(query) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. If transaction is a read-only transaction, throw a “[ReadOnlyError](https://www.w3.org/TR/WebIDL-1/#readonlyerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  6. Let range be the result of running the steps to convert a value to a key range with query and null disallowed flag set. Rethrow any exceptions.

  7. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to delete records from an object store as operation, using store and range.

The query parameter may be a key or an [IDBKeyRange](#idbkeyrange) identifying the records keys to be deleted.

Unlike other methods which take keys or key ranges, this method does not allow null to be given as key. This is to reduce the risk that a small bug would clear a whole object store.

The clear() method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. If transaction is a read-only transaction, throw a “[ReadOnlyError](https://www.w3.org/TR/WebIDL-1/#readonlyerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  6. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to clear an object store as operation, using store.

The following methods throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) if called when the transaction is not active.

request = store . [get](#dom-idbobjectstore-get)(query)

Retrieves the value of the first record matching the given key or key range in query.

If successful, request’s [result](#dom-idbrequest-result) will be the value, or undefined if there was no matching record.

request = store . [getKey](#dom-idbobjectstore-getkey)(query)

Retrieves the key of the first record matching the given key or key range in query.

If successful, request’s [result](#dom-idbrequest-result) will be the key, or undefined if there was no matching record.

request = store . [getAll](#dom-idbobjectstore-getall)(query [, count])

Retrieves the values of the records matching the given key or key range in query (up to count if given).

If successful, request’s [result](#dom-idbrequest-result) will be an Array of the values.

request = store . [getAllKeys](#dom-idbobjectstore-getallkeys)(query [, count])

Retrieves the keys of records matching the given key or key range in query (up to count if given).

If successful, request’s [result](#dom-idbrequest-result) will be an Array of the keys.

request = store . [count](#dom-idbobjectstore-count)(query)

Retrieves the number of records matching the given key or key range in query.

If successful, request’s [result](#dom-idbrequest-result) will be the count.

The get(query) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. Let range be the result of running the steps to convert a value to a key range with query and null disallowed flag set. Rethrow any exceptions.

  6. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to retrieve a value from an object store as operation, using the current Realm as targetRealm, store and range.

The query parameter may be a key or an [IDBKeyRange](#idbkeyrange) identifying the record to be retrieved. If a range is specified, the method retrieves the first existing value in that range.

This method produces the same result if a record with the given key doesn’t exist as when a record exists, but has undefined as value. If you need to tell the two situations apart, you can use [openCursor()](#dom-idbobjectstore-opencursor) with the same key. This will return a cursor with undefined as value if a record exists, or no cursor if no such record exists.

The getKey(query) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. Let range be the result of running the steps to convert a value to a key range with query and null disallowed flag set. Rethrow any exceptions.

  6. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to retrieve a key from an object store as operation, using store and range.

The query parameter may be a key or an [IDBKeyRange](#idbkeyrange) identifying the record key to be retrieved. If a range is specified, the method retrieves the first existing key in that range.

🚧 The [getKey()](#dom-idbobjectstore-getkey) method on [IDBObjectStore](#idbobjectstore) is new in this edition. It is supported in Chrome 58, Firefox 51, and Safari 10.1. 🚧

The getAll(query, count) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. Let range be the result of running the steps to convert a value to a key range with query. Rethrow any exceptions.

  6. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to retrieve multiple values from an object store as operation, using the current Realm as targetRealm, store, range, and count if given.

The query parameter may be a key or an [IDBKeyRange](#idbkeyrange) identifying the records to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count records in range, only the first count will be retrieved.

🚧 The [getAll()](#dom-idbobjectstore-getall) method is new in this edition. It is supported in Chrome 48, Firefox 44, and Safari 10.1. 🚧

The getAllKeys(query, count) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. Let range be the result of running the steps to convert a value to a key range with query. Rethrow any exceptions.

  6. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to retrieve multiple keys from an object store as operation, using store, range, and count if given.

The query parameter may be a key or an [IDBKeyRange](#idbkeyrange) identifying the records keys to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count keys in range, only the first count will be retrieved.

🚧 The [getAllKeys()](#dom-idbobjectstore-getallkeys) method is new in this edition. It is supported in Chrome 48, Firefox 44, and Safari 10.1. 🚧

The count(query) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. Let range be the result of running the steps to convert a value to a key range with query. Rethrow any exceptions.

  6. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to count the records in a range as operation, with source and range.

The query parameter may be a key or an [IDBKeyRange](#idbkeyrange) identifying the records keys to be counted. If null or not given, an unbounded key range is used.

The following methods throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) if called when the transaction is not active.

request = store . [openCursor](#dom-idbobjectstore-opencursor)([query [, direction = “next”]])

Opens a cursor over the records matching query, ordered by direction. If query is null, all records in store are matched.

If successful, request’s [result](#dom-idbrequest-result) will be an [IDBCursorWithValue](#idbcursorwithvalue) pointing at the first matching record, or null if there were no matching records.

request = store . [openKeyCursor](#dom-idbobjectstore-openkeycursor)([query [, direction = “next”]])

Opens a cursor with key only flag set over the records matching query, ordered by direction. If query is null, all records in store are matched.

If successful, request’s [result](#dom-idbrequest-result) will be an [IDBCursor](#idbcursor) pointing at the first matching record, or null if there were no matching records.

The openCursor(query, direction) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. Let range be the result of running the steps to convert a value to a key range with query. Rethrow any exceptions.

  6. Let cursor be a new cursor with transaction set to transaction, an undefined position, direction set to direction, got value flag unset, and undefined key and value. The source of cursor is store. The range of cursor is range.

  7. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to iterate a cursor as operation, using the current Realm as targetRealm, and cursor.

The query parameter may be a key or an [IDBKeyRange](#idbkeyrange) to use as the cursor‘s range. If null or not given, an unbounded key range is used.

The openKeyCursor(query, direction) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. Let range be the result of running the steps to convert a value to a key range with query. Rethrow any exceptions.

  6. Let cursor be a new cursor with transaction set to transaction, an undefined position, direction set to direction, got value flag unset, and undefined key and value. The source of cursor is store. The range of cursor is range. The key only flag of cursor is set.

  7. Run the steps to asynchronously execute a request and return the [IDBRequest](#idbrequest) created by these steps. The steps are run with this object store handle as source and the steps to iterate a cursor as operation, using the current Realm as targetRealm, and cursor.

The query parameter may be a key or an [IDBKeyRange](#idbkeyrange) to use as the cursor‘s range. If null or not given, an unbounded key range is used.

🚧 The [openKeyCursor()](#dom-idbobjectstore-openkeycursor) method is new in this edition. It is supported in Chrome 48, Firefox 44, and Safari 10.1. 🚧

index = store . index(name)

Returns an [IDBIndex](#idbindex) for the index named name in store.

index = store . [createIndex](#dom-idbobjectstore-createindex)(name, keyPath [, options])

Creates a new index in store with the given name, keyPath and options and returns a new [IDBIndex](#idbindex). If the keyPath and options define constraints that cannot be satisfied with the data already in store the upgrade transaction will abort with a “[ConstraintError](https://www.w3.org/TR/WebIDL-1/#constrainterror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

Throws an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) if not called within an upgrade transaction.

store . [deleteIndex](#dom-idbobjectstore-deleteindex)(name)

Deletes the index in store with the given name.

Throws an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) if not called within an upgrade transaction.

The createIndex(name, keyPath, options) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If transaction is not an upgrade transaction, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  6. If an index named name already exists in store, throw a “[ConstraintError](https://www.w3.org/TR/WebIDL-1/#constrainterror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  7. If keyPath is not a valid key path, throw a “[SyntaxError](https://www.w3.org/TR/WebIDL-1/#syntaxerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  8. Let unique be set if options’s [unique](#dom-idbindexparameters-unique) member is true, and unset otherwise.

  9. Let multiEntry be set if options’s [multiEntry](#dom-idbindexparameters-multientry) member is true, and unset otherwise.

  10. If keyPath is a sequence and multiEntry is set, throw an “[InvalidAccessError](https://www.w3.org/TR/WebIDL-1/#invalidaccesserror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  11. Let index be a new index in store. Set index’s name to name and key path to keyPath. If unique is set, set index’s unique flag. If multiEntry is set, set index’s multiEntry flag.

  12. Add index to this object store handle‘s index set.

  13. Return a new index handle associated with index and this object store handle.

This method creates and returns a new index with the given name in the object store. Note that this method must only be called from within an upgrade transaction.

The index that is requested to be created can contain constraints on the data allowed in the index’s referenced object store, such as requiring uniqueness of the values referenced by the index’s keyPath. If the referenced object store already contains data which violates these constraints, this must not cause the implementation of [createIndex()](#dom-idbobjectstore-createindex) to throw an exception or affect what it returns. The implementation must still create and return an [IDBIndex](#idbindex) object, and the implementation must queue a task to abort the upgrade transaction which was used for the [createIndex()](#dom-idbobjectstore-createindex) call.

This method synchronously modifies the [indexNames](#dom-idbobjectstore-indexnames) property on the [IDBObjectStore](#idbobjectstore) instance on which it was called. Although this method does not return an [IDBRequest](#idbrequest) object, the index creation itself is processed as an asynchronous request within the upgrade transaction.

In some implementations it is possible for the implementation to asynchronously run into problems creating the index after the createIndex method has returned. For example in implementations where metadata about the newly created index is queued up to be inserted into the database asynchronously, or where the implementation might need to ask the user for permission for quota reasons. Such implementations must still create and return an [IDBIndex](#idbindex) object, and once the implementation determines that creating the index has failed, it must abort the transaction using the steps to abort a transaction using an appropriate error as error. For example if creating the index failed due to quota reasons, a “[QuotaExceededError](https://www.w3.org/TR/WebIDL-1/#quotaexceedederror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) must be used as error and if the index can’t be created due to unique flag constraints, a “[ConstraintError](https://www.w3.org/TR/WebIDL-1/#constrainterror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) must be used as error.

The asynchronous creation of indexes is observable in the following example:

  1. var request1 = objectStore.put({name: "betty"}, 1);
  2. var request2 = objectStore.put({name: "betty"}, 2);
  3. var index = objectStore.createIndex("by_name", "name", {unique: true});

At the point where [createIndex()](#dom-idbobjectstore-createindex) called, neither of the requests have executed. When the second request executes, a duplicate name is created. Since the index creation is considered an asynchronous request, the index’s uniqueness constraint does not cause the second request to fail. Instead, the transaction will be aborted when the index is created and the constraint fails.

The index(name) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If transaction has finished, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. Let index be the index named name in this object store handle‘s index set if one exists, or throw a “[NotFoundError](https://www.w3.org/TR/WebIDL-1/#notfounderror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) otherwise.

  6. Return an index handle associated with index and this object store handle.

Each call to this method on the same [IDBObjectStore](#idbobjectstore) instance with the same name returns the same [IDBIndex](#idbindex) instance.

The returned [IDBIndex](#idbindex) instance is specific to this [IDBObjectStore](#idbobjectstore) instance. If this method is called on a different [IDBObjectStore](#idbobjectstore) instance with the same name, a different [IDBIndex](#idbindex) instance is returned.

The deleteIndex(name) method, when invoked, must run these steps:

  1. Let transaction be this object store handle‘s transaction.

  2. Let store be this object store handle‘s object store.

  3. If transaction is not an upgrade transaction, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  4. If store has been deleted, throw an “[InvalidStateError](https://www.w3.org/TR/WebIDL-1/#invalidstateerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. If transaction is not active, throw a “[TransactionInactiveError](https://www.w3.org/TR/WebIDL-1/#transactioninactiveerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  6. Let index be the index named name in store if one exists, or throw a “[NotFoundError](https://www.w3.org/TR/WebIDL-1/#notfounderror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) otherwise.

  7. Remove index from this object store handle‘s index set.

  8. Destroy index.

This method destroys the index with the given name in the object store. Note that this method must only be called from within an upgrade transaction.

This method synchronously modifies the [indexNames](#dom-idbobjectstore-indexnames) property on the [IDBObjectStore](#idbobjectstore) instance on which it was called. Although this method does not return an [IDBRequest](#idbrequest) object, the index destruction itself is processed as an asynchronous request within the upgrade transaction.