IDBFactory: deleteDatabase() method
The deleteDatabase()
method of the IDBFactory
interface requests the deletion of a database. The method returns an IDBOpenDBRequest
object immediately, and performs the deletion operation asynchronously.
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 undefined
. 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.
When deleteDatabase()
is called, any other open connections to this particular database will get a versionchange event.
Syntax
deleteDatabase(name)
deleteDatabase(name)
deleteDatabase(name, options)
Parameters
-
name
-
The name of the database you want to delete. Note that attempting to delete a database that doesn't exist does not throw an exception, in contrast to IDBDatabase.deleteObjectStore()
, which does throw an exception if the named object store does not exist.
options
Optional Non-standard
-
In Gecko, since version 26, you can include a non-standard 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.)
Return value
A IDBOpenDBRequest
on which subsequent events related to this request are fired.
If the operation is successful, the value of the request's result
property is null
.
Examples
const DBDeleteRequest = window.indexedDB.deleteDatabase("toDoList");
DBDeleteRequest.onerror = (event) => {
console.error("Error deleting database.");
};
DBDeleteRequest.onsuccess = (event) => {
console.log("Database deleted successfully");
console.log(event.result);
};
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
deleteDatabase |
23 |
12 |
10 |
10 |
15 |
8 |
4.4 |
25 |
22 |
14 |
8 |
1.5 |
See also