IDBObjectStore.clear

This article is in need of a technical review.

« IDBObjectStore

The IDBObjectStore.clear method creates and immediately returns an IDBRequest object, and clears this object store in a separate thread.

Clearing an object store consists of removing all records from the object store and removing all records in indexes that reference the object store.

Syntax

 IDBRequest clear ();

Example

// Let us open our database
var request = window.indexedDB.open("toDoList", 4);

// Create an objectStore for this database
 
var objectStore = db.createObjectStore("toDoList", { keyPath: "taskTitle" });

// define what data items the objectStore will contain

objectStore.createIndex("hours", "hours", { unique: false });
objectStore.createIndex("minutes", "minutes", { unique: false });
objectStore.createIndex("day", "day", { unique: false });
objectStore.createIndex("month", "month", { unique: false });
objectStore.createIndex("year", "year", { unique: false });

objectStore.createIndex("notified", "notified", { unique: false });

note.innerHTML += '<li>Object store created.</li>';

// clear the object store again

objectStore.clear();

Returns

IDBRequest
A request object on which subsequent events related to this operation are fired.

Exceptions

This method may raise a DOMException with a DOMError of the following types:

Exception Description
ReadOnlyError The transaction associated with this operation is in read-only mode.
TransactionInactiveError This IDBObjectStore's transaction is inactive.

 

Specifications

Specification Status Comment
Indexed Database API Candidate Recommendation  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 12 4.0 (2.0) 10 17 Not supported
count() 23 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
count() 4.4 ? 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.

See also

  • Using IndexedDB
  • The reference application for the examples in this reference: To-do Notifications (view example live.) Not every snippet appears in this example, but every example uses the same data structure and syntax, and they will make sense in the context of this example.

Document Tags and Contributors

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