docs.rodeo

MDN Web Docs mirror

IDBDatabase: close() method

{{ APIRef("IndexedDB") }}  {{AvailableInWorkers}} 

The close() method of the {{domxref("IDBDatabase")}}  interface 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.

Syntax

close()

Parameters

None.

Return value

None ({{jsxref("undefined")}} ).

Examples

// Let us open our database
const DBOpenRequest = window.indexedDB.open("toDoList", 4); // opening a database.

// Create event handlers for both success and failure of
DBOpenRequest.onerror = (event) => {
  note.appendChild(document.createElement("li")).textContent =
    "Error loading database.";
};

DBOpenRequest.onsuccess = (event) => {
  note.appendChild(document.createElement("li")).textContent =
    "Database initialized.";

  // store the result of opening the database in the db variable.
  db = DBOpenRequest.result;

  // now let's close the database again!
  db.close();
};

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN