Warning: The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.
The IDBObjectStoreSync
interface of the IndexedDB API provides synchronous access to an object store of a database.
any add (in any value, in optional any key) raises
(IDBDatabaseException); |
IDBIndexSync createIndex (in DOMString name, in
DOMString storeName, in DOMString keypath, in optional boolean
unique); |
any get (in any key) raises (IDBDatabaseException); |
IDBCursorSync
openCursor (in optional
IDBKeyRange range, in
optional unsigned short direction) raises (IDBDatabaseException); |
IDBIndexSync
openIndex (in DOMString name) raises (IDBDatabaseException); |
any put (in any value, in optional any key) raises
(IDBDatabaseException); |
void remove (in any key) raises (IDBDatabaseException); |
void removeIndex (in DOMString
indexName) raises (IDBDatabaseException); |
Attribute | Type | Description |
---|---|---|
indexNames | readonly DOMStringList | A list of the names of the indexes on this object store. |
keyPath | readonly DOMString | The key path of this object store. If this attribute is set to null, then the application must provide a key for each modification operation. |
mode | readonly unsigned short | The mode for isolating access to the data in this object store. For possible values, see Constants. |
name | readonly DOMString | The name of this object store. |
Constant | Value | Description |
---|---|---|
READ_ONLY | 1 | Modification operations are not allowed on this object store. |
READ_WRITE | 0 | Modification operations are allowed on this object store. |
SNAPSHOT_READ | 2 | Any read operations must access a snapshot view of the data, which cannot change once it is created. |
Stores the given value into this object store, optionally with the specified key. If a record already exists with the given key, an exception is raised.
any add( in any value, in optional any key ) raises (IDBDatabaseException);
This method can raise a IDBDatabaseException with the following codes:
The value to store into the index.
A key to use for identifying the record.
any
The key for the stored record.
CONSTRAINT_ERR
If a record exists in this index with a key corresponding to the key parameter or the index is auto-populated, or if no record exists with a key corresponding to the value parameter in the index's referenced object store.
DATA_ERR
If this object store uses out-of-line keys, and the key parameter was not passed.
SERIAL_ERR
If the data being stored could not be serialized by the internal structured cloning algorithm.
Creates and returns a new index with the given name in the connected database.
IDBIndexSync createIndex ( in DOMString name, in DOMString keypath, in optional boolean unique );
The name of a new index.
The key path used by the new index.
If true, keys in the index must be unique; if false, duplicate keys are allowed.
IDBIndexSync
An object to access the newly created index.
Retrieves and returns the value from this object store for the record that corresponds to the given key.
any get ( in any key ) raises (IDBDatabaseException);
The key that identifies the record to be retrieved.
any
The value retrieved from the object store.
This method can raise a IDBDatabaseException with the following codes:
SERIAL_ERR
If the data being stored could not be deserialized by the internal structured cloning algorithm.
NOT_FOUND_ERR
If no record exists in this index for the given key.
Creates a cursor over the records of this object store. The range of the new cursor matches the specified key range; if the key range is not specified or is null, then the range includes all the records.
CursorSync openCursor ( in optional KeyRange range, in optional unsigned short direction ) raises (DatabaseException);
The key range to use as the cursor's range.
The cursor's required direction.
IDBIndexSync
An object for accessing the index.
This method can raise a DatabaseException with the following code:
NOT_FOUND_ERR
If no records exist in this index for the requested key range.
Opens the index with the given name, using the mode of the current transaction.
IDBIndexSync openIndex ( in DOMString name ) raises (IDBDatabaseException);
The name of the index to open.
IDBIndexSync
An object to access the index.
This method can raise an IDBDatabaseException with the following code:
NOT_FOUND_ERR
If the index with the given name does not exist in the connected database.
Stores the given value in this object store and returns the key for the stored record. If a record already exists with the given key, it is overwritten.
any put ( in any value, in optional any key ) raises (IDBDatabaseException);
The value to be stored in the record.
The key to be used to identify the record.
any
The key for the stored record.
This method can raise an IDBDatabaseException with the following codes:
CONSTRAINT_ERR
If noOverwrite was true, and a record exists in this index for the given key or this index is auto-populated; or if no record exists with the given key in the index's referenced object store.
DATA_ERR
If this object store uses out-of-line keys and no key generator, but no key was given.
SERIAL_ERR
If the data being stored could not be serialized by the internal structured cloning algorithm.
Removes from this object store any records that correspond to the given key.
void remove ( in any key ) raises (IDBDatabaseException);
Key of the records to be removed.
This method can raise a IDBDatabaseException with the following code:
NOT_FOUND_ERR
If a record does not exist in this index with the given key.
Destroys an index with the given name.
void removeIndex ( in DOMString indexName ) raises (IDBDatabaseException);
The name of the existing index to remove.
This method can raise an IDBDatabaseException with the following code:
NOT_FOUND_ERR
If an index with the given name does not exist in the connected database.
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStoreSync