transaction method
Begins a transaction for the specified object stores.
![]() |
Syntax
var retVal = IDBDatabase.transaction(storeNames, mode);Parameters
- storeNames [in]
-
Type: any
If specified, defines the names of the object stores included in the transaction. Use a DOMString to specify a single object store or an array of DOMString values to specify multiple object stores.
- mode [in, optional]
-
Type: DOMString
Value Meaning - readonly
Changes are not allowed in this transaction.
- readwrite
Changes are allowed in this transaction.
- versionchange
Objects in the database can be created.
Exceptions
This method can throw the following DOMException exceptions:
| Exception properties | Condition |
|---|---|
|
The value of the storeNames parameter is blank or otherwise invalid. | |
|
The database has been closed or a transaction has been request for an object that has been deleted or is otherwise unavailable. | |
|
A specified object store could not be found in the current database (case-sensitive). | |
|
The value of the mode parameter is not supported. |
Standards information
Remarks
While read-only and read/write transactions can be initiated with the transaction method, version change transactions occur only within the context of an upgradeneeded event, which can only be triggered by opening a database with a higher version number. For more info, see open.
Examples
The following example uses the transaction method to open an object store to a set of records and then calls a function with the cursor matching those records. For more info, see Managing data with transactions.
if ( hIxHandle == null ) { handleError( "Can't open database (invalid handle)." ); } else try { sObjectStore = getCardStoreName(); var hTransaction = hDBHandle.transaction( sObjectStore, "readonly" ); var hObjectStore = hTransaction.objectStore( sObjectStore ); var hRequest = hObjectStore.openCursor( aValue ); hRequest.onerror = handleErrorEvent( evt ); hRequest.onsuccess = function( evt ) { if ( fnCallback != null ) { var oResult = null; // assume no result. if ( evt.target.result != null ) { oResult = evt.target.result.value; } doSomething( oResult ); } } } catch( ex ) { handleError( ex.message ); }
See also
