IDBFactory Interface
The IDBFactory
interface of the IndexedDB API lets applications asynchronously access the indexed databases. The object that implements the interface is window.indexedDB
. You open—that is, create and access—and delete a database with the object and not directly with IDBFactory
.
This interface still has vendor prefixes, that is to say, you have to make calls with mozIndexedDB.open()
for Firefox and webkitIndexedDB.open()
for Chrome.
Methods
Code int cmp(first, second) #
Compares two values as keys to determine equality and ordering for IndexedDB operations, such as storing and iterating. Do not use this method for comparing arbitrary JavaScript values, because many JavaScript values are either not valid IndexedDB keys (booleans and objects, for example) or are treated as equivalent IndexedDB keys (for example, since IndexedDB ignores arrays with non-numeric properties and treats them as empty arrays, so any non-numeric array are treated as equivalent).
This throws an exception if either of the values is not a valid key.
Parameters
- first
- The first key to compare.
- second
- The second key to compare.
Returns
- Integer
-
Returned value Description -1 1st key < 2nd 0 1st key = 2nd 1 1st key > 2nd
Exceptions
This method can raise an IDBDatabaseException with the following code:
Attribute | Description |
---|---|
NON_TRANSIENT_ERR | One of the supplied keys was not a valid key. |
int cmp(/*IDBKey*/ first, /*IDBKey*/ second);
Code IDBVersionChangeRequest deleteDatabase(String name) #
Request deleting a database. The method returns an IDBRequest object immediately, and performs the deletion operation asynchronously.
The deletion operation (performed in a different thread) consists of the following steps:
- If there is no database with the given name, exit successfully.
- Fire an IDBVersionChangeEvent at all connection objects connected to the named database, with
version
set tonull
. - If any connection objects connected to the database are still open, fire a
blocked
event at the request object returned by thedeleteDatabase
method, using IDBVersionChangeEvent withversion
set tonull
. - Wait until all open connections to the database are closed.
- Delete the database.
If the database is successfully deleted, then an IDBSuccessEvent 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, with its code
and message
set to appropriate values.
Tip: If the browser you are using hasn't implemented this yet, you can delete the object stores one by one, thus effectively removing the database.
Parameters
- name
- The name of the database.
Returns
IDBRequest
- A request object on which subsequent events related to this request are fired. In the latest draft of the specification, which has not yet been implemented by browsers, the returned object is
IDBOpenRequest
.
IDBVersionChangeRequest deleteDatabase(String name);
Code IDBRequest open(String name) #
Request opening a connection to a database. The method returns an IDBRequest object immediately, and performs the opening operation asynchronously.
The opening operation—which is performed in a separate thread—consists of the following steps:
- If a database named
myAwesomeDatabase
already exists:- Wait until any existing
VERSION_CHANGE
transactions have finished. - If the database has a deletion pending, wait until it has been deleted.
- Wait until any existing
- If no database with that name exists, create a database with the provided name, with the empty string as its version, and no object stores.
- Create a connection to the database.
If the operation is successful, an IDBSuccessEvent is fired on the request object that is returned from this method, with its result attribute set to the new IDBDatabase object for the connection.
If an error occurs while the database connection is being opened, then an error event is fired on the request object returned from this method, with its code
and message
set to appropriate values.
Parameters
- name
- The name of the database.
- version
- The version of the database.
Returns
IDBRequest
- A request object on which subsequent events related to this request are fired. In the latest draft of the specification, which has not yet been implemented by browsers, the returned object is
IDBOpenRequest
.
IDBRequest open(String name);
Code IDBRequest webkitGetDatabaseNames() #
IDBRequest webkitGetDatabaseNames();
This page includes content from the Mozilla Foundation that is graciously licensed under a Creative Commons: Attribution-Sharealike license. Mozilla has no other association with Dart or dartlang.org. We encourage you to improve the web by contributing to The Mozilla Developer Network.