createObjectStore method

Creates an object store.

Internet Explorer 10

Syntax

var retVal = IDBDatabase.createObjectStore(name, optionalParameters);

Parameters

name [in]

Type: DOMString

The name of the object store to be created.

optionalParameters [in, optional]

Type: any

An object literal containing one or more of the following attributes.

ValueMeaning
keyPath

A DOMString value specifying the keypath for the object store

autoIncrement

A Boolean value indicating whether the key value automatically increases as records are added to the object store.

 

retVal [out, retval]

Type: IDBObjectStore

Exceptions

This method can throw the following DOMException exceptions:

Note  As of Internet Explorer 10, the code property is deprecated in favor of the name property, which is preferred for standards compliance and future compatibility.

Exception propertiesCondition
name: InvalidStateError
code: DOMException.INVALID_STATE_ERR (11)

The method was not called within the context of a VERSION_CHANGE transaction or the request was made for an object that has been moved or deleted.

name: ConstraintError

An object store in the database already uses the name (case-sensitive).

name: InvalidAccessError

The autoIncrement attribute of the optionalParameters object is true; however, the keyPath attribute either an empty string ("") or an empty array.

Standards information

Examples

The following example shows createObjectStore being called in the context of an upgradeneeded event. For more info, see Creating and opening IndexedDB objects.


  if ( hIxHandle == null ) {
     handleError( "Can't open database (invalid handle)." );
  } else
       try {
          var sDBName = "ADatabase";
          var nDBVersion = 1.0;
          var req = hIxHandle.open( sDBName, nDBVersion );
          req.onsuccess = function(evt) { 
             hDBHandle = evt.target.result;
          }      
          req.onerror = handleRequestEvent;
          req.onblocked = handleRequestEvent;
          req.onupgradeneeded = function(evt) {
             var hDBHandle = evt.target.result;
             var sStoreName = "MyObjectStore";
             var oDBOptions = { keyPath : "RecordID", autoIncrement : true };
             var oStore = hDBHandle.createObjectStore( sStoreName, oDBOptions );

             var oIxOptions = { unique: false, multientry: false };
             oStore.createIndex( "SortByTitle", "DeckTitle", oIxOptions );
             oStore.createIndex( "SortByDesc", "Description", oIxOptions );
          }
       } catch( ex ) {
         handleError( ex.message );
       }   


See also

IDBDatabase

 

 

Show:
© 2014 Microsoft