createObjectStore method
Creates an object store.
![]() |
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.
- retVal [out, retval]
-
Type: IDBObjectStore
Exceptions
This method can throw the following DOMException exceptions:
| Exception properties | Condition |
|---|---|
|
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. | |
|
An object store in the database already uses the name (case-sensitive). |
|
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
