This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

IDBVersionChangeEvent

Summary

The IDBVersionChangeEvent object represents the event object passed to the upgradeneeded event, which fires when a database is opened using a higher version number.


Properties

newVersion
Returns the new version of the database, which is the version specified by the open request.
oldVersion
Returns the old version of the database.


Methods

No methods.

Events

No events.

Examples

In this example, properties from the IDBVersionChangeEvent object passed to the upgradeneeded event are used by the createDatabaseObjects function (not shown):

try {
  var req = window.indexedDB.open( "MyDatabase", 1.0 );
  req.onsuccess = doDatabaseWork; 
  req.onerror = handleErrorEvent;
  req.onblocked = handleBlockedEvent;
  req.onupgradeneeded = function(evt) {
    createDatabaseObjects( 
       evt.target.result, evt.target.transaction, 
       evt.oldVersion, evt.newVersion );
  }
} catch( ex ) {
  handleException( ex.message );
}


Usage

 When you open a database, you include a version number.  If the supplied version number is greater than the version of the database on the user's device (if any), an upgradeneeded event is fired within the context of a version change transaction.  This context lets you create (or modify) object stores, indexes, ranges, and other database objects.

For more information about transaction types, see IDBTransaction mode.

Notes

The upgradeneeded event fires before the success event, which can lead to issues when attempting to cache handles.

Related specifications

W3C IndexedDB Specification
W3C Proposed Recommendation

See also

External resources

Attributions