Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

indexedDB.deleteDatabase — deleting an entire database

indexedDB.deleteDatabase(name) asynchronously deletes the named database, including its data and structure. It returns a request, not a Promise. Open connections can block the operation; the success event confirms completion.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

const request = indexedDB.deleteDatabase(name);

indexedDB.deleteDatabase(name) deletes the entire named database, including object stores, indexes, and records, in the current storage scope. It does not delete just one record or merely close a connection. The operation is destructive; use only the intended name.

The call returns an IDBOpenDBRequest, not a Promise: await indexedDB.deleteDatabase(name) does not wait for deletion. Handle success, error, and blocked. An absent database also produces success. Read asynchronous errors from request.error; the call itself can also throw a synchronous SecurityError.

IndexedDB sends versionchange with newVersion === null to open connections that are not already marked close-pending. When handling this event, generally call db.close() and stop using the connection. A connection already marked close-pending skips this notification but can still block deletion until its outstanding transactions finish. If any connection remains open, the request fires blocked and waits. This does not mean cancellation or failure, nor does it mean every blocking connection was notified. Connections in other tabs count too.

This is a Web API, not a feature of a particular ECMAScript edition. Node 24 in a repository does not establish browser support. Run the example in a browser that exposes IndexedDB. Storage access is required for deletion to succeed, but not to run the example. The code handles denied access, which is what the displayed output Deletion failed: SecurityError illustrates.

Examples

(async () => {
  const name = `cktis-delete-${crypto.getRandomValues(new Uint32Array(4)).join('-')}`;
  const result = request => new Promise((resolve, reject) => {
    request.onsuccess = () => resolve(request.result);
    request.onerror = () => reject(request.error);
  });

  try {
    try {
      const seed = indexedDB.open(name, 1);
      seed.onupgradeneeded = () => {
        seed.result.createObjectStore('items').put('fixture', 'key');
      };
      const db = await result(seed);
      db.close();
    } catch (error) {
      if (error.name !== 'SecurityError') throw error;
      // Still exercise deleteDatabase when fixture creation is denied.
    }

    const deletion = indexedDB.deleteDatabase(name);
    deletion.onblocked = () => console.log('Deletion blocked by an open connection');
    deletion.onerror = () => console.log(`Deletion failed: ${deletion.error.name}`);
    deletion.onsuccess = event => {
      console.log(`Deletion complete: old version ${event.oldVersion}, new version ${event.newVersion}`);
    };
  } catch (error) {
    console.log(`Deletion failed: ${error.name}`);
  }
})();

Result

Deletion failed: SecurityError

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources