IndexedDB

IndexedDB is an API for client-side storage of significant amounts of structured data and for high performance searches on this data using indexes. While DOM Storage is useful for storing smaller amounts of data, it is less useful for storing larger amounts of structured data. IndexedDB provides a solution.

This page is basically the entry point for the technical description of the API objects. If you need a primer you should consult Basic Concepts About IndexedDB. For a lot more details, see Using IndexedDB.

IndexedDB provides separate APIs for synchronous and asynchronous access. The synchronous API is intended to be used only inside of Web Workers but it isn't implemented by any browser yet. The asynchronous API works both within and without Web Workers, but Firefox hasn't implemented this yet.

Asynchronous API

The asynchronous API methods return without blocking the calling thread. To get asynchronous access to a database, call open() on the indexedDB attribute of a window object. This method returns an IDBRequest object (IDBOpenDBRequest); asynchronous operations communicate to the calling application by firing events on IDBRequest objects.

Note: The indexedDB object is prefixed in older browser versions (property mozIndexedDB in Gecko < 16, webkitIndexedDB in Chrome, and msIndexedDB in IE 10).

  • IDBFactory provides access to a database. This is the interface implemented by the global object indexedDB and is therefore the entry point for the API.
  • IDBCursor iterates over object stores and indexes.
  • IDBCursorWithValue iterates over object stores and indexes and returns the cursor's current value.
  • IDBDatabase represents a connection to a database. It's the only way to get a transaction on the database.
  • IDBEnvironment provides access to a client-side database. It is implemented by window objects.
  • IDBIndex provides access to the metadata of an index.
  • IDBKeyRange defines a range of keys.
  • IDBObjectStore represents an object store.
  • IDBOpenDBRequest represents a request to open a database.
  • IDBRequest provides access to results of asynchronous requests to databases and database objects. It is what you get when you call an asynchronous method.
  • IDBTransaction represents a transaction. You create a transaction on a database, specify the scope (such as which object stores you want to access), and determine the kind of access (read only or write) that you want.
  • IDBVersionChangeEvent indicates that the version of the database has changed.

An early version of the specification also defined these now removed interfaces. They are still documented in case you need to update previously written code:

There is also a synchronous version of the API.  The Synchronous API has not been implemented in any browser.  It is intended for use with WebWorkers.

Storage limits

There isn't any limit on a single database item's size. However there may be a limit on each IndexedDB database's size. This limit (and the way the user interface will assert it) may vary from one browser to another:

Example

A powerful example of what IndexedDB can be utilized for on the web is the example by Marco Castelluccio, winner of the IndexedDB Mozilla DevDerby. The winning demo was eLibri, a library and eBook reader application.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Asynchronous API

24.0
11.0 webkit

16.0 (16.0)
4.0 (2.0) moz
10 15.0 Нет
Synchronous API
(used with WebWorkers)
Нет Нет
See баг 701634
Нет Нет Нет
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Asynchronous API Нет 6.0 (6.0) moz Нет Нет Нет

There is also the possibility of using IndexedDB on browsers that support WebSQL by using an IndexedDB Polyfill or Shim.

See also

Метки документа и участники

 Внесли вклад в эту страницу: madarche
 Обновлялась последний раз: madarche,