indexeddb

< apis(Redirected from apis/indexedDB)
Jump to: navigation, search

Indexed Database API

This article is Ready to Use.

W3C Proposed Recommendation

Summary

IndexedDB is a client side storage API that persists data in a user's browser. It is a transactional, non-relational storage mechanism that saves key-value pairs in Object Stores and allows searching data using indexes.


API Name Summary
IDBCursorWithValue Returns the IDBCursor's value.
IDBDatabase Represents a database connection for the purpose of conducting a transaction.
IDBDatabaseException Not supported.
IDBFactory The object type for the indexedDB property, which provides access to the IndexedDB features supported by the browser and/or device.
IDBIndex A metadata index to a referenced object store.
IDBKeyRange A range of keys defined for an object store or index.
IDBOpenDBRequest Provides access to the result of a request to open a database.
IDBTransaction Provides for the scope and type of access to a database, and represents a transaction on the database.
IDBVersionChangeEvent The IDBVersionChangeEvent object represents the event object passed to the upgradeneeded event, which fires when a database is opened using a higher version number.
IDBVersionChangeRequest Deprecated; no longer in spec.

Used to change the version of the database.


Usage

 IndexedDB enables you to store large amounts of data in a reliable and structured way. If you are building web applications that need to work offline the API can be useful to store, group, iterate, search, and filter JavaScript objects.

Notes

The IndexedDB specification supports an Asynchronous API on the window object and a Synchronous API for Webworkers.

An IndexedDB database is made up of Object Stores. Object stores can be created and JavaScript objects of any shape can be stored inside of them. Every object can have different properties, just because they are in the same Object Store it doesn't mean that they need to have the same structure. The only requirement is that the object has properties that match any explicit Keys or Indexes that you have set up on the Object store.


Constructs

Database

Each origin has a set of associated databases. Database comprise of Object Stores that store data

Object Store

Object Stores have list of records which hold data as key-value pairs. Every Object Store belongs to a database.

Keys

Every record in an object store is stored as key-value pairs. Keys are indexed for easy retrieval of data. A valid key can be an Array, Date, DOMString or float. Keys can either be generated automatically using a key generator, or specified during data insertion. Keys can also be derived from values using a key path attribute specified for an Object Store

Values

Every record has a value that contains the data for a record. A value must be supported by the Structured Cloning Algorithm.

Index

An index allows looking up records in an object store using properties of the values in the object stores records. An index is a specialized persistent key-value storage and has a referenced object store. The index has a list of records which hold the data stored in the index. The records in an index are automatically populated whenever records in the referenced object store are inserted, updated or deleted. There can be several indexes referencing the same object store, in which changes to the object store cause all such indexes to get updated.

Cursor

A cursor is a transient construct to iterate over the records in a database. Cursors can be used on Object Stores or Indexes

Transaction

All database read and write operations occur in transactions. Transactions can be read or read_write. A version_change transaction is a special transaction that allows adding or deleting Object Stores or Indexes.

Request

Each reading and writing operation on a database is done using a request. The result of a request is usually available in success or error events raised on the request.

Security

The IndexedDB storage follows the same-origin policy.

An IndexedDB database is unique for our domain. So if we set up a database only we are going to be able to see it and the Object stores inside of it. If you use a shared domain, then everyone sharing your domain will be able to access and work with the data in your IndexedDB.


Storage Limits

  • Firefox will just ask the user for permission for blobs bigger than 50 MB. Reference
  • For Google Chrome, see the reference on temporary storage
  • Internet Explorer will ask the user for permission for Data Stores bigger than 10MB Users can also choose to allow websites to exceed the quota. Users can also change the default 10mb quota in Internet Options > Browsing History > Settings > Caching and Databases. Enterprises can also increase this setting globally or per domain using Group Policy.
  • Windows 8 Apps Each app has a quota of 250MB. Among all apps on the device, the limit is 4% of the disk size or 20GB, whichever is smaller. For hard drives that are less than 30GB, the limit among all apps on the device is 375MB. Because of the overall quota among all apps, test your app to ensure it functions properly when it can store very little or even no data because other apps consume the overall quota. See: [1]


See also

Other articles

Tutorials and Walkthroughs:

External resources

Library

  • IDBWrapper Ease the use of indexedDB and abstract away the differences between the existing implementations in Chrome, Firefox and IE10 (yes, it works in all three). Show how IDB works. The code is split up into short methods, so that it's easy to see what happens in what method.[2]



  • YDN-DB Javascript database module for Indexeddb, Web SQL and localStorage storage mechanisms supporting version migration, advanced query, SQL and transaction. API Documentations