IDBFactory.deleteDatabase

« IDBFactory

The IDBFactory.deleteDatabase method requests the deletion of a database. The method returns an IDBOpenDBRequest object immediately, and performs the deletion operation asynchronously.

The deletion operation (performed in a different thread) consists of the following steps:

  1. If there is no database with the given name, exit successfully.
  2. Fire an IDBVersionChangeEvent at all connection objects connected to the named database, with version set to null.
  3. If any connection objects connected to the database are still open, fire a blocked event at the request object returned by the deleteDatabase method, using IDBVersionChangeEvent with version set to null.
  4. Wait until all open connections to the database are closed.
  5. Delete the database.

If the database is successfully deleted, then a success event is fired on the request object returned from this method, with its result set to null. If an error occurs while the database is being deleted, then an error event is fired on the request object that is returned from this method.

Syntax

For the current standard:

IDBOpenDBRequest deleteDatabase (DOMString name);

For the experimental version with options (see below):

IDBOpenDBRequest deleteDatabase (DOMString name, optional IDBOpenDBOptions options);

Example

For the current standard:

var request = window.indexedDB.deleteDatabase("toDoList");

For the experimental version with options (see below):

var request = window.indexedDB.deleteDatabase("toDoList", storage: "temporary");

Parameters

name
The name of the database.
options Non-standard
In Gecko, since version 26, you can include a optional storage parameter that specifies whether you want to delete a permanent (the default value) IndexedDB, or an indexedDB in temporary storage (aka shared pool.) See bug 785884 for more details. This is a non-standard feature that we are looking to standardise sometime in the future.

Note: Data in temporary storage persists until the global limit for the pool is reached. The global limit calculation is relatively complex, but we are considering changing it (see  bug 968272). When the global limit is reached, then data for the least recently used origin is deleted. There's also a group limit (eTLD+1 group/domain) which is currently 20% of the global limit. All requets that would exceed the group limit are just rejected.

Returns

IDBOpenDBRequest
The request object on which subsequent events related to this request are fired.

Specifications

Specification Status Comment
Indexed Database API Candidate Recommendation  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 12webkit
24
10.0 (10.0) 10 17 Not supported
Feature Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support 4.4 6.0 (6.0) 1.0.1 10 17 Not supported

 

Be careful in Chrome as it still implements the old specification along the new one. Similarly it still has the prefixed webkitIndexedDB property even if the unprefixed indexedDB is present.

 

Document Tags and Contributors

Contributors to this page: chrisdavidmills
Last updated by: chrisdavidmills,