createIndex method

Creates an index on an object store.

Internet Explorer 10

Syntax

var retVal = IDBObjectStore.createIndex(name, keyPath, optionalParameters);

Parameters

name [in]

Type: DOMString

Name of the index.

keyPath [in]

Type: any

Name of the field to be indexed.

optionalParameters [in, optional]

Type: object

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

ValueMeaning
unique

A Boolean value indicating whether the index allows duplicate values. If this attribute is true, duplicate values are not allowed. Duplicate values are allowed when this attribute is false (the default value).

multiEntry

A Boolean value that determines the results when multiple rows in the object store match individual key values. When this happens, the resulting object is an array. If this parameter is true, the resulting array contains a single item; the key of the item contains an array of the matching values. When this parameter is false (the default), the result array contains one item for each item that matches the key value.

Note  Multi-entry indexes are not supported by Internet Explorer 10 or Windows Store apps.

 

Return value

Type: IDBIndex

An object representing the new index.

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: ConstraintError

An index with the same name (case-sensitive) already exists in the database.

name: InvalidStateError
code: DOMException.INVALID_STATE_ERR (11)

Either the associated transaction is not a "versionchange" transaction or the object store has been deleted from the database.

Standards information

Examples

The following example shows uses the createIndex method to create three indexes for an object store.


      var oDBOptions = { keyPath : "RecordID", autoIncrement : true };
      var oStore = dbHandle.createObjectStore( "CardDecks", oDBOptions );

      var oIxOptions = { unique: false, multientry: false };
      oStore.createIndex( "IxDecksByTitle", "DeckTitle", oIxOptions );
      oStore.createIndex( "IxDecksBySortOrder", "SortOrder", oIxOptions );
      oStore.createIndex( "IxDecksByDesc", "Description", oIxOptions );


See also

IDBObjectStore

 

 

Show:
© 2014 Microsoft