Revision 63175 of IDBDatabase

  • Revision slug: IndexedDB/IDBDatabase
  • Revision title: IDBDatabase
  • Revision id: 63175
  • Created:
  • Creator: josiewern
  • Is current revision? No
  • Comment 1 words added, 1 words removed

Revision Content

The IDBDatabase interface of the IndexedDB API provides asynchronous access to a connection to a database. You use it to create, manipulate, and delete objects in that database. It also provides the only way to get a transaction and manage versions on that database.

Inherits from: EventTarget

About this document

This document was last updated on October 10, 2011 and follows the W3C Specifications (Editor's Draft) drafted on August 25, 2011. The specification has since changed, but none of the browsers have implemented the changes yet. So this article documents what is currently supported by the browsers, not what is defined in the latest specification. Be aware that some methods have either changed or been dropped in the latest version of the specification.

This document has not yet been verified.

Basic concepts

To create create, manipulate, and delete objects in the database, do the following:

  1. Open a connection to the database (using indexedDB.open()).

    An IDBRequest object is returned. All asynchronous methods return that object.

  2. Attach event listeners to the IDBRequest object.

    If the open request is successful, the onsuccess callback is executed.

  3. Check the version of the database to ensure that you are not stomping on changes the user might have made in other tabs that have been opened to your application.

    When the other tabs have finished their transactions, the database closes the transaction and sends a success event.

  4. If the database is not the expected version, call setVersion(). Only under setVersion() can you create and delete object stores and indexes. But if you are just modifying an existing object store, a normal write transaction would do; you don't have to call the setVersion() method.

    An IDBRequest object is returned.

  5. Attach callbacks to the IDBRequest object.

  6. If the callback is successful, create or delete the object store.

Example

In the following code snippet, we open a database asynchronously and make a request.  Because the specification is still evolving, Chrome and Firefox put prefixes in the methods. Chrome uses the webkit prefix while Firefox uses the moz prefix. Event handlers are registered for responding to various situations.

// Taking care of the browser-specific prefixes.
if ('webkitIndexedDB' in window) {
   window.indexedDB = window.webkitIndexedDB;
   window.IDBTransaction = window.webkitIDBTransaction;
} else if ('mozIndexedDB' in window) {
   window.indexedDB = window.mozIndexedDB;
}


//Open a connection to the database with the name "creatures" 
//with the empty string as its version.  

var creatures = {};
creatures.indexedDB = {};

creatures.indexedDB.open = function() {
  var request = indexedDB.open("creatures");

  //The open request isn't executed yet, but an IDBRequest object is returned. 
  //Create listeners to the IDBRequest. 
  //If the open request is successful, the onsuccess callback is executed. 

  request.onsuccess = function(event) {
    var version = "1.0 beta";
    creatures.indexedDB.db = event.target.result;
    var db = creatures.indexedDB.db;

    //Check the database version, which is a string. 
    //If it isn't the expected version, call setVersion().     
    //setVersion() is where you can create and delete object stores and indexes. 
    
    if(version != db.version) {
      var setVersionRequest = db.setVersion(version);

      // setVersion() returns IDBRequest object.
      // Attach callbacks to IDBRequest. 

      setVersionRequest.onsuccess = function(event) {

        // If it's successful, create an object store called "swamp"
        // and define an optional parameter object, the "terrorizedPopulace" keyPath.        
        // The keyPath must be what makes an object unique and every object must have it.  
        // If every creature had a unique identification number, that would also be a good keyPath. 
        
        var datastore = db.createObjectStore("swamp",
          {keyPath: "terrorizedPopulace"});

       setVersionRequest.onfailure = creatures.indexedDB.onerror;  

        //After the object store is created, call the method, getAllSwampCreatures. 
        creatures.indexedDB.getAllSwampCreatures();
      };
                  
    }

    creatures.indexedDB.getAllSwampCreatures();
  };

  request.onfailure = creatures.indexedDB.onerror;
}

Method overview

IDBObjectStore createObjectStore (in DOMString name, in optional Object optionalParameters) raises (IDBDatabaseException);
IDBRequest deleteObjectStore (in DOMString name) raises (IDBDatabaseException);
IDBVersionChangeRequest setVersion ([TreatNullAs=EmptyString] in DOMString version);
IDBTransaction transaction (in any storeNames, in optional unsigned short mode) raises (IDBDatabaseException);
void close();

Attributes

Attribute Type Description
name readonly DOMString Name name of the connected database.
version readonly DOMString The version of the connected database. When a database is first created, this attribute is the empty string.
objectStoreNames readonly DOMStringList A list of the names of the object stores currently in the connected database.

Methods

createObjectStore()

Creates and returns a new object store or index. The method takes the name of the store as well as a parameter object. The parameter object lets you define important optional properties. You can use the property to uniquely identify individual objects in the store. As the property is an identifier, it should be unique to every object, and every object should have that property.

But before you can create any object store or index, you must first call the setVersion() method.

This is because the method can be called only within a VERSION_CHANGE transaction. As discussed in the Basic Concepts, all changes that you make to the database must happen within a transaction. Transactions have modes, and object stores and indexes can only be created under the VERSION_CHANGE mode. The mode is for updating the version number of transactions that were started using the setVersion() method. Transactions of this mode cannot run concurrently with other transactions.

IDBObjectStore createObjectStore(
  in DOMString name,
  in Object optionalParameters
) raises (IDBDatabaseException);
Parameters
name
The name of the new object store.
optionalParameters
Warning: The latest draft of the specification changed this to IDBDatabaseOptionalParameters, which is not yet recognized by any browser

Options object whose attributes are optional parameters to the method. It includes the following properties:

Attribute Description
keyPath The key path to be used by the new object store. If empty or not specified, the object store is created without a key path and uses out-of-line keys.
autoIncrement If true, the object store has a key generator. Defaults to false.
Returns
IDBObjectStore
The newly created object store.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

Attribute Description
NOT_ALLOWED_ERR The method was not called from a VERSION_CHANGE transaction callback. You must call setVersion() first.
CONSTRAINT_ERR An object store with the given name (based on case-sensitive comparison) already exists in the connected database.
NON_TRANSIENT_ERR optionalParameters has attributes other than keyPath and autoIncrement.

deleteObjectStore()

Destroys the object store with the given name in the connected database, along with any indexes that reference it. 

As with createObjectStore(), this method can be called only within a VERSION_CHANGE transaction. In other words, you must call the setVersion() method first before you can remove any object store or index.

IDBRequest deleteObjectStore(
  in DOMString name
) raises (IDBDatabaseException);
Parameters
name
The name of the data store to delete.
Returns

void

Exceptions

This method can raise an IDBDatabaseException with the following codes:

Attribute Description
NOT_ALLOWED_ERR The method was not called from a VERSION_CHANGE transaction callback. You must call setVersion() first.
NOT_FOUND_ERR You are trying to delete an object store that does not exist. Names are case sensitive.

setVersion()

Warning: The latest draft of the specification dropped this method. Naturally, when the new specification is implemented by browsers, the way you set versions and the way you create and delete object stores change.

Updates the version of the database. Returns immediately and runs a VERSION_CHANGE transaction on the connected database in a separate thread.

Call this method before you can create or delete an object store.

IDBVersionChangeRequest setVersion(
  in DOMString version
) raises (IDBDatabaseException);
Parameters
version
The version to store in the database.
Returns
IDBVersionChangeRequest
The request to change the version of a database.

transaction()

Immediately returns an IDBTransaction object, and starts a transaction in a separate thread.

IDBTransaction transaction(
  in optional any storeNames,
  in optional unsigned short mode  
) raises (IDBDatabaseException);
Parameters
Returns
Exceptions

This method can raise an IDBDatabaseException with the following codes:

Attribute Description
NOT_ALLOWED_ERR The error is thrown for one of two reasons:
  • The close() method has been called on this IDBDatabase instance.
  • The object store has been deleted or removed.
NOT_FOUND_ERR One of the object stores doesn't exist in the connected database.
NON_TRANSIENT_ERR optionalParameters has attributes other than keyPath and autoIncrement.

close()

Returns immediately and closes the connection in a separate thread. The connection is not actually closed until all transactions created using this connection are complete. No new transactions can be created for this connection once this method is called. Methods that create transactions throw an exception if a closing operation is pending.

void close();

Event handlers

Event handler Event handler type
onabort Abort
onerror Error
onversionchange Version change

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 12{{ property_prefix("-webkit") }} {{ CompatGeckoDesktop("2.0") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatNo() }} {{ CompatGeckoMobile("6.0") }} {{ CompatUnknown() }} {{ CompatNo() }} {{ CompatNo() }}

Revision Source

<p>The <code>IDBDatabase</code> interface of the IndexedDB API provides asynchronous access to a <a href="/en/IndexedDB#database_connection" title="en/IndexedDB#database connection">connection to a database</a>. You use it to create, manipulate, and delete objects in that database. It also provides the only way to get a <a href="/en/IndexedDB#gloss_transaction" title="en/IndexedDB#gloss transaction">transaction</a> and manage versions on that database.</p>
<p>Inherits from: <a href="/en/DOM/EventTarget" title="en/DOM/EventTarget">EventTarget</a></p>
<h2>About this document</h2>
<p>This document was last updated on October 10, 2011 and follows the <a class="external" href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#request-api">W3C Specifications (Editor's Draft)</a> drafted on August 25, 2011. The specification has since changed, but none of the browsers have implemented the changes yet. So this article documents what is currently supported by the browsers, not what is defined in the latest specification. Be aware that some methods have either changed or been dropped in the latest version of the specification.</p>
<p>This document has not yet been verified.</p>
<h2>Basic concepts</h2>
<p>To create create, manipulate, and delete objects in the database, do the following:</p>
<ol> <li>Open a connection to the database (using <a href="/en/IndexedDB/IDBFactory#open()" title="en/IndexedDB/IDBFactory#open()">indexedDB.open()</a>). <p>An <code><a href="/en/IndexedDB/IDBRequest" title="en/IndexedDB/IDBRequest">IDBRequest</a></code> object is returned. All asynchronous methods return that object.</p> </li> <li>Attach event listeners to the IDBRequest object. <p>If the open request is successful, the <code>onsuccess</code> callback is executed.</p> </li> <li>Check the version of the database to ensure that you are not stomping on changes the user might have made in other tabs that have been opened to your application. <p>When the other tabs have finished their transactions, the database closes the transaction and sends a success event.</p> </li> <li>If the database is not the expected version, call <code>setVersion()</code>. Only under <code>setVersion()</code> can you create and delete object stores and indexes. But if you are just modifying an existing object store, a normal <a href="/en/IndexedDB/IDBTransaction" title="en/IndexedDB/IDBTransaction">write transaction</a> would do; you don't have to call the <code>setVersion()</code> method. <p>An <code>IDBRequest</code> object is returned.</p> </li> <li> <p>Attach callbacks to the <code>IDBRequest</code> object.</p> </li> <li>If the callback is successful, create or delete the object store.</li>
</ol>
<h3>Example</h3>
<p>In the following code snippet, we open a database asynchronously and make a request.  Because the specification is still evolving, Chrome and Firefox put prefixes in the methods. Chrome uses the <code>webkit</code> prefix while Firefox uses the <code>moz</code> prefix. Event handlers are registered for responding to various situations.</p>
<pre class="brush: js">// Taking care of the browser-specific prefixes.
if ('webkitIndexedDB' in window) {
   window.indexedDB = window.webkitIndexedDB;
   window.IDBTransaction = window.webkitIDBTransaction;
} else if ('mozIndexedDB' in window) {
   window.indexedDB = window.mozIndexedDB;
}


//Open a connection to the database with the name "creatures" 
//with the empty string as its version.  

var creatures = {};
creatures.indexedDB = {};

creatures.indexedDB.open = function() {
  var request = indexedDB.open("creatures");

  //The open request isn't executed yet, but an IDBRequest object is returned. 
  //Create listeners to the IDBRequest. 
  //If the open request is successful, the onsuccess callback is executed. 

  request.onsuccess = function(event) {
    var version = "1.0 beta";
    creatures.indexedDB.db = event.target.result;
    var db = creatures.indexedDB.db;

    //Check the database version, which is a string. 
    //If it isn't the expected version, call setVersion().     
    //setVersion() is where you can create and delete object stores and indexes. 
    
    if(version != db.version) {
      var setVersionRequest = db.setVersion(version);

      // setVersion() returns IDBRequest object.
      // Attach callbacks to IDBRequest. 

      setVersionRequest.onsuccess = function(event) {

        // If it's successful, create an object store called "swamp"
        // and define an optional parameter object, the "terrorizedPopulace" keyPath.        
        // The keyPath must be what makes an object unique and every object must have it.  
        // If every creature had a unique identification number, that would also be a good keyPath. 
        
        var datastore = db.createObjectStore("swamp",
          {keyPath: "terrorizedPopulace"});

       setVersionRequest.onfailure = creatures.indexedDB.onerror;  

        //After the object store is created, call the method, getAllSwampCreatures. 
        creatures.indexedDB.getAllSwampCreatures();
      };
                  
    }

    creatures.indexedDB.getAllSwampCreatures();
  };

  request.onfailure = creatures.indexedDB.onerror;
}</pre>
<h2>Method overview</h2>
<table class="standard-table"> <tbody> <tr> <td><code><a href="/en/IndexedDB/IDBObjectStore" title="en/IndexedDB/IDBObjectStore">IDBObjectStore</a> <a href="#createObjectStore" title="#createObjectStore">createObjectStore</a> (in DOMString <em>name</em>, in optional Object <em>optionalParameters</em>) raises (<a href="/en/IndexedDB/IDBDatabaseException" title="en/IndexedDB/IDBDatabaseException">IDBDatabaseException</a>); </code></td> </tr> <tr> <td><code><a href="/en/IndexedDB/IDBRequest" title="en/IndexedDB/IDBRequest">IDBRequest</a> <a href="#deleteObjectStore" title="#deleteObjectStore">deleteObjectStore</a> (in <a href="/En/DOM/DOMString" title="en/DOM/DOMString">DOMString</a> <em>name</em>) </code><code>raises (<a href="/en/IndexedDB/IDBDatabaseException" title="en/IndexedDB/IDBDatabaseException">IDBDatabaseException</a>);</code></td> </tr> <tr> <td><code><a href="/en/IndexedDB/IDBVersionChangeRequest" title="en/IndexedDB/IDBVersionChangeRequest">IDBVersionChangeRequest</a> <a href="#setVersion" title="#setVersion">setVersion</a> ([TreatNullAs=EmptyString] in <a href="/En/DOM/DOMString" title="en/DOM/DOMString">DOMString</a> <em>version</em>); </code></td> </tr> <tr> <td><code><a href="/en/IndexedDB/IDBTransaction" title="en/IndexedDB/IDBTransaction">IDBTransaction</a> <a href="#transaction" title="#transaction">transaction</a> (in any <em>storeNames</em>, in optional unsigned short <em>mode</em>) </code><code>raises (<a href="/en/IndexedDB/IDBDatabaseException" title="en/IndexedDB/IDBDatabaseException">IDBDatabaseException</a>); </code></td> </tr> <tr> <td><code>void <a href="/#close" title="#close">close</a>();</code></td> </tr> </tbody>
</table>
<h2>Attributes</h2>
<table class="standard-table"> <thead> <tr> <th scope="col">Attribute</th> <th scope="col">Type</th> <th scope="col">Description</th> </tr> </thead> <tbody> <tr> <td><code><a name="attr_name">name</a></code></td> <td><code>readonly DOMString </code></td> <td>Name name of the connected database.</td> </tr> <tr> <td><code><a name="attr_version">version</a></code></td> <td><code>readonly DOMString </code></td> <td>The version of the connected database. When a database is first created, this attribute is the empty string.</td> </tr> <tr> <td><code><a name="attr_objectStores">objectStoreNames</a></code></td> <td><code>readonly DOMStringList </code></td> <td>A list of the names of the <a href="/en/IndexedDB#gloss_object_store" title="en/IndexedDB#gloss object store">object stores</a> currently in the connected database.</td> </tr> </tbody>
</table>
<h2>Methods</h2>
<h3 name="createObjectStore">createObjectStore()</h3>
<p>Creates and returns a new object store or index. The method takes the name of the store as well as a parameter object. The parameter object lets you define important optional properties. You can use the property to uniquely identify individual objects in the store. As the property is an identifier, it should be unique to every object, and every object should have that property.</p>
<p>But before you can create any object store or index, you must first call the <code><a href="#setVersion()">setVersion()</a></code><a href="#setVersion()"> method</a>.</p>
<p>This is because the method can be called <em>only</em> within a <code><a href="/en/IndexedDB/IDBTransaction#VERSION_CHANGE" title="en/IndexedDB/IDBTransaction#VERSION CHANGE">VERSION_CHANGE</a></code> transaction. As discussed in the <a href="/en/IndexedDB/Basic_Concepts_Behind_IndexedDB" title="en/IndexedDB/Basic_Concepts_Behind_IndexedDB">Basic Concepts</a>, all changes that you make to the database must happen within a transaction. Transactions have modes, and object stores and indexes can only be created under the <code>VERSION_CHANGE</code> mode. The mode is for updating the version number of transactions that were started using the <code>setVersion()</code> method. Transactions of this mode cannot run concurrently with other transactions.</p>
<pre>IDBObjectStore createObjectStore(
  in DOMString <em>name</em>,
  in <code>Object <em>optionalParameters</em></code>
) raises (IDBDatabaseException);
</pre>
<h5>Parameters</h5>
<dl> <dt>name</dt> <dd>The name of the new object store.</dd> <dt>optionalParameters</dt> <dd> <div class="warning"><strong>Warning:</strong> The latest draft of the specification changed this to <code>IDBDatabaseOptionalParameters</code>, which is not yet recognized by any browser</div> <p>Options object whose attributes are optional parameters to the method. It includes the following properties:</p> <table class="standard-table"> <thead> <tr> <th scope="col" width="131">Attribute</th> <th scope="col" width="698">Description</th> </tr> </thead> <tbody> <tr> <td><code>keyPath</code></td> <td>The <a href="/en/IndexedDB#gloss_key_path" title="en/IndexedDB#gloss key path">key path</a> to be used by the new object store. If empty or not specified, the object store is created without a key path and uses <a href="/en/IndexedDB#gloss_out-of-line_key" title="en/IndexedDB#gloss out-of-line key">out-of-line keys</a>.</td> </tr> <tr> <td><code>autoIncrement</code></td> <td>If true, the object store has a <a href="/en/IndexedDB#gloss_key_generator" title="en/IndexedDB#gloss key generator">key generator</a>. Defaults to <code>false</code>.</td> </tr> </tbody> </table> </dd>
</dl>
<h5>Returns</h5>
<dl> <dt><code><a href="/en/IndexedDB/IDBObjectStore" title="en/IndexedDB/IDBObjectStore">IDBObjectStore</a></code></dt> <dd>The newly created object store.</dd>
</dl>
<h5>Exceptions</h5>
<p>This method can raise an <a href="/en/IndexedDB/IDBDatabaseException" title="en/IndexedDB/IDBDatabaseException">IDBDatabaseException</a> with the following codes:</p>
<table class="standard-table"> <thead> <tr> <th scope="col" width="131">Attribute</th> <th scope="col" width="698">Description</th> </tr> </thead> <tbody> <tr> <td><code><a href="/en/IndexedDB/IDBDatabaseException#NOT_ALLOWED_ERR" title="en/IndexedDB/DatabaseException#NOT ALLOWED ERR">NOT_ALLOWED_ERR</a></code></td> <td>The method was not called from a <code><a href="/en/IndexedDB/IDBTransaction#VERSION_CHANGE" title="en/IndexedDB/IDBTransaction#VERSION CHANGE">VERSION_CHANGE</a></code> transaction callback. You must call <code>setVersion()</code> first.</td> </tr> <tr> <td><code><a href="/en/IndexedDB/IDBDatabaseException#CONSTRAINT_ERR" title="en/IndexedDB/DatabaseException#CONSTRAINT ERR">CONSTRAINT_ERR</a></code></td> <td>An object store with the given name (based on case-sensitive comparison) already exists in the connected database.</td> </tr> <tr> <td><code><a href="/en/IndexedDB/IDBDatabaseException#NON_TRANSIENT_ERR" title="en/IndexedDB/IDBDatabaseException#NON_TRANSIENT_ERR">NON_TRANSIENT_ERR</a></code></td> <td><code>optionalParameters</code> has attributes other than <code>keyPath</code> and <code>autoIncrement</code>.</td> </tr> </tbody>
</table>
<h3>deleteObjectStore()</h3>
<p>Destroys the object store with the given name in the connected database, along with any indexes that reference it. </p>
<p>As with <code>createObjectStore()</code>, this method can be called <em>only</em> within a <code><a href="/en/IndexedDB/IDBTransaction#VERSION_CHANGE" title="en/IndexedDB/IDBTransaction#VERSION CHANGE">VERSION_CHANGE</a></code> transaction. In other words, you must call the <code>setVersion()</code> method first before you can remove any object store or index.</p>
<pre>IDBRequest deleteObjectStore(
  in DOMString <em>name</em>
) raises (IDBDatabaseException);
</pre>
<h5>Parameters</h5>
<dl> <dt>name</dt> <dd>The name of the data store to delete.</dd>
</dl>
<h5>Returns</h5>
<p><code>void</code></p>
<h5>Exceptions</h5>
<p>This method can raise an <a href="/en/IndexedDB/IDBDatabaseException" title="en/IndexedDB/IDBDatabaseException">IDBDatabaseException</a> with the following codes:</p>
<table class="standard-table"> <thead> <tr> <th scope="col" width="131">Attribute</th> <th scope="col" width="698">Description</th> </tr> </thead> <tbody> <tr> <td><code><a href="/en/IndexedDB/IDBDatabaseException#NOT_ALLOWED_ERR" title="en/IndexedDB/DatabaseException#NOT ALLOWED ERR">NOT_ALLOWED_ERR</a></code></td> <td>The method was not called from a <code><a href="/en/IndexedDB/IDBTransaction#VERSION_CHANGE" title="en/IndexedDB/IDBTransaction#VERSION CHANGE">VERSION_CHANGE</a></code> transaction callback. You must call <code>setVersion()</code> first.</td> </tr> <tr> <td><code><a href="/en/IndexedDB/IDBDatabaseException#NOT_FOUND_ERR" title="en/IndexedDB/IDBDatabaseException#NOT FOUND ERR">NOT_FOUND_ERR</a></code></td> <td>You are trying to delete an object store that does not exist. Names are case sensitive.</td> </tr> </tbody>
</table>
<h3 name="setVersion()">setVersion()</h3>
<div class="warning"><strong>Warning:</strong> The latest draft of the specification dropped this method. Naturally, when the new specification is implemented by browsers, the way you set versions and the way you create and delete object stores change.</div>
<p>Updates the version of the database. Returns immediately and runs a <code><a href="/en/IndexedDB/IDBTransaction#VERSION_CHANGE" title="en/IndexedDB/IDBTransaction#VERSION CHANGE">VERSION_CHANGE</a></code> transaction on the connected database in a separate thread.</p>
<p>Call this method before you can create or delete an object store.</p>
<!--Setting the version of the database&nbsp;makes sure upgrades to new "schemas" goes smoothly. If you&nbsp;roll out a new version of the site that requires a new schema in the&nbsp;database, you run the risk of having a user who has multiple tabs open to different versions of your database. Some of the tabs could have been opened before the new version was rolled out, while the rest of the tabs could have been opened&nbsp;after the new version had been rolled out. Setting the version&nbsp;ensures that the tabs with the old versions don't write invalid data&nbsp;into the database after the tab with the latest version has upgraded the database&nbsp;to the new "schema." --><pre>IDBVersionChangeRequest setVersion(
  in DOMString <em>version</em>
) raises (IDBDatabaseException);
</pre>
<h5>Parameters</h5>
<dl> <dt>version</dt> <dd>The version to store in the database.</dd>
</dl>
<h5>Returns</h5>
<dl> <dt><code><a href="/en/IndexedDB/IDBVersionChangeRequest" title="en/IndexedDB/IDBObjectStore">IDBVersionChangeRequest</a></code></dt> <dd>The request to change the version of a database.</dd>
</dl>
<h3 name="transaction">transaction()</h3>
<p>Immediately returns an <a href="/en/IndexedDB/IDBTransaction" title="en/IndexedDB/IDBTransaction">IDBTransaction</a> object, and starts a transaction in a separate thread.</p>
<pre>IDBTransaction transaction(
  in optional any <em>storeNames</em>,
  in optional unsigned short <em>mode</em>  
) raises (IDBDatabaseException);
</pre>
<h5>Parameters</h5>
<h5>Returns</h5>
<h5>Exceptions</h5>
<p>This method can raise an <a href="/en/IndexedDB/IDBDatabaseException" title="en/IndexedDB/IDBDatabaseException">IDBDatabaseException</a> with the following codes:</p>
<table class="standard-table"> <thead> <tr> <th scope="col" width="131">Attribute</th> <th scope="col" width="698">Description</th> </tr> </thead> <tbody> <tr> <td><code><a href="/en/IndexedDB/IDBDatabaseException#NOT_ALLOWED_ERR" title="en/IndexedDB/DatabaseException#NOT ALLOWED ERR">NOT_ALLOWED_ERR</a></code></td> <td>The error is thrown for one of two reasons: <ul> <li>The <code>close()</code> method has been called on this IDBDatabase instance.</li> <li>The object store has been deleted or removed.</li> </ul> </td> </tr> <tr> <td><code><a href="/en/IndexedDB/IDBDatabaseException#NOT_FOUND_ERR" title="en/IndexedDB/IDBDatabaseException#NOT FOUND ERR">NOT_FOUND_ERR</a></code></td> <td>One of the object stores doesn't exist in the connected database.</td> </tr> <tr> <td><code><a href="/en/IndexedDB/IDBDatabaseException#NON_TRANSIENT_ERR" title="en/IndexedDB/IDBDatabaseException#NON_TRANSIENT_ERR">NON_TRANSIENT_ERR</a></code></td> <td><code>optionalParameters</code> has attributes other than <code>keyPath</code> and <code>autoIncrement</code>.</td> </tr> </tbody>
</table>
<h3>close()</h3>
<p>Returns immediately and closes the connection in a separate thread. The connection is not actually closed until all transactions created using this connection are complete. No new transactions can be created for this connection once this method is called. Methods that create transactions throw an exception if a closing operation is pending.</p>
<pre>void close();
</pre>
<h2>Event handlers</h2>
<table border="1" cellpadding="1" cellspacing="1" class="standard-table"> <thead> <tr> <th scope="col" width="165">Event handler</th> <th scope="col" width="280">Event handler type</th> </tr> </thead> <tbody> <tr> <td><code>onabort</code></td> <td>Abort</td> </tr> <tr> <td><code>onerror</code></td> <td>Error</td> </tr> <tr> <td><code>onversionchange</code></td> <td>Version change</td> </tr> </tbody>
</table>
<h2 name="Browser_Compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>Basic support</td> <td>12{{ property_prefix("-webkit") }}</td> <td>{{ CompatGeckoDesktop("2.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatNo() }}</td> <td>{{ CompatGeckoMobile("6.0") }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
Revert to this revision