-
Notifications
You must be signed in to change notification settings - Fork 0
createIndex
Kristof degrave edited this page Apr 12, 2017
·
1 revision
The createIndex function creates a new index on an object store in the indexeddb database. If the index all ready exists, the existing index is retrieved.
- objectStore:
- An object store or a object store promise object
- propertyName
- The name of the property on which the index is based
- indexOptions
- Extra options for creating an index
- unique: boolean value that adds an unique constraint for the property
- multirow: boolean value that adds all individual values inside the array of the given property as key. for more info see http://www.kristofdegrave.be/2012/09/indexeddb-multientry-explained.html.
- indexName: string value that defines the name of the index. (When not present the propertyName + a suffix is used as name.)
- Optional
- Default unique: false & multirow: true
- Extra options for creating an index
The function returns a promise object with 2 callbacks
- Success callback
- The index was created & retrieved successfully
- The first argument contains transaction.
- The second argument contains the index
- The third argument contains the object store
- Error callback
- Creating the index failed
- The argument object contains a custom error object.
- InvalidStateError:
- You are trying to create an object store in an non VERSION_CHANGE transaction.
{{ linq2indexedDB.core.db("name", 1).then( function (){}, function (){} function (args){ var transaction = args0; if(args1.type == 'upgradeneeded'){ var objectStorePromise = linq2indexedDB.core.objectStore(transaction, "objectstore"); linq2indexedDB.core.index(objectStore, "property").then(success, error); } });
function success(args){ var transaction= args0; var index = args1; var objectstore= args2; } function error(args){ var error= args; } }}