Class: IDBStore

IDBStore

new IDBStore(kwArgs, onStoreReady)

The IDBStore constructor

Parameters:
Name Type Argument Description
kwArgs Object <optional>
An options object used to configure the store and set callbacks
Properties
Name Type Argument Default Description
storeName String <optional>
'Store' The name of the store
storePrefix String <optional>
'IDBWrapper-' A prefix that is internally used to construct the name of the database, which will be kwArgs.storePrefix + kwArgs.storeName
dbVersion Number <optional>
1 The version of the store
keyPath String <optional>
'id' The key path to use
autoIncrement Boolean <optional>
true If set to true, IDBStore will automatically make sure a unique keyPath value is present on each object that is stored.
onStoreReady Function <optional>
A callback to be called when the store is ready to be used.
onError Function <optional>
throw A callback to be called when an error occurred during instantiation of the store.
indexes Array <optional>
[] An array of indexData objects defining the indexes to use with the store. For every index to be used one indexData object needs to be passed in the array. An indexData object is defined as follows:
Properties
Name Type Argument Description
indexData Object <optional>
An object defining the index to use
Properties
Name Type Argument Description
name String The name of the index
keyPath String <optional>
The key path of the index
unique Boolean <optional>
Whether the index is unique
multiEntry Boolean <optional>
Whether the index is multi entry
onStoreReady Function <optional>
A callback to be called when the store is ready to be used.
Version:
  • 1.0.0
Source:
  • IDBWrapper/idbstore.js, line 38
Examples
      // create a store for customers with an additional index over the
      // `lastname` property.
      var myCustomerStore = new IDBStore({
        dbVersion: 1,
        storeName: 'customer-index',
        keyPath: 'customerid',
        autoIncrement: true,
        onStoreReady: populateTable,
        indexes: [
          { name: 'lastname', keyPath: 'lastname', unique: false, multiEntry: false }
        ]
      });
      // create a generic store
      var myCustomerStore = new IDBStore({
        storeName: 'my-data-store',
        onStoreReady: function(){
          // start working with the store.
        }
      });

Members

<static> autoIncrement :Boolean

Whether IDBStore uses autoIncrement

Source:
  • IDBWrapper/idbstore.js, line 179

<static> db :Object

A reference to the IndexedDB object

Source:
  • IDBWrapper/idbstore.js, line 136

<static> dbName :String

The full name of the IndexedDB used by IDBStore, composed of this.storePrefix + this.storeName

Source:
  • IDBWrapper/idbstore.js, line 144

<static> dbVersion :Number

The version of the IndexedDB used by IDBStore

Source:
  • IDBWrapper/idbstore.js, line 151

<static> features :Object

A hashmap of features of the used IDB implementation

Source:
  • IDBWrapper/idbstore.js, line 195

<static> indexes :Array

The indexes used by IDBStore

Source:
  • IDBWrapper/idbstore.js, line 186

<static> keyPath :String

The key path

Source:
  • IDBWrapper/idbstore.js, line 172

<static> onError :Function

The callback to be called if an error occurred during instantiation of the store

Source:
  • IDBWrapper/idbstore.js, line 210

<static> onStoreReady :Function

The callback to be called when the store is ready to be used

Source:
  • IDBWrapper/idbstore.js, line 202

<static> store :Object

A reference to the objectStore used by IDBStore

Source:
  • IDBWrapper/idbstore.js, line 158

<static> storeName :String

The store name

Source:
  • IDBWrapper/idbstore.js, line 165

<static> version :String

The version of IDBStore

Source:
  • IDBWrapper/idbstore.js, line 129

Methods

<static> batch(dataArray, onSuccess, onError)

Runs a batch of put and/or remove operations on the store.

Parameters:
Name Type Argument Description
dataArray Array An array of objects containing the operation to run and the data object (for put operations).
onSuccess Function <optional>
A callback that is called if all operations were successful.
onError Function <optional>
A callback that is called if an error occurred during one of the operations.
Source:
  • IDBWrapper/idbstore.js, line 448

<static> clear(onSuccess, onError)

Clears the store, i.e. deletes all entries in the store.

Parameters:
Name Type Argument Description
onSuccess Function <optional>
A callback that will be called if the operation was successful.
onError Function <optional>
A callback that will be called if an error occurred during the operation.
Source:
  • IDBWrapper/idbstore.js, line 568

<static> count(onSuccess, options)

Runs a query against the store, but only returns the number of matches instead of the matches itself.

Parameters:
Name Type Argument Description
onSuccess Function A callback to be called if the opration was successful.
options Object <optional>
An object defining specific options
Properties
Name Type Argument Default Description
index Object <optional>
null An IDBIndex to operate on
keyRange Object <optional>
null An IDBKeyRange to use
onError Function <optional>
console.error A callback to be called if an error occurred during the operation.
Source:
  • IDBWrapper/idbstore.js, line 755

<static> deleteDatabase()

Deletes the database used for this store if the IDB implementations provides that functionality.

Source:
  • IDBWrapper/idbstore.js, line 356

<static> get(key, onSuccess, onError)

Retrieves an object from the store. If no entry exists with the given id, the success handler will be called with null as first and only argument.

Parameters:
Name Type Argument Description
key * The id of the object to fetch.
onSuccess Function <optional>
A callback that is called if fetching was successful. Will receive the object as only argument.
onError Function <optional>
A callback that will be called if an error occurred during the operation.
Source:
  • IDBWrapper/idbstore.js, line 403

<static> getAll(onSuccess, onError)

Fetches all entries in the store.

Parameters:
Name Type Argument Description
onSuccess Function <optional>
A callback that is called if the operation was successful. Will receive an array of objects.
onError Function <optional>
A callback that will be called if an error occurred during the operation.
Source:
  • IDBWrapper/idbstore.js, line 513

<static> getIndexList() → {DOMStringList}

Returns a DOMStringList of index names of the store.

Source:
  • IDBWrapper/idbstore.js, line 603
Returns:
The list of index names
Type
DOMStringList

<static> hasIndex(indexName) → {Boolean}

Checks if an index with the given name exists in the store.

Parameters:
Name Type Description
indexName String The name of the index to look for
Source:
  • IDBWrapper/idbstore.js, line 613
Returns:
Whether the store contains an index with the given name
Type
Boolean

<static> indexComplies(actual, expected) → {Boolean}

Checks if an actual index complies with an expected index.

Parameters:
Name Type Description
actual Object The actual index found in the store
expected Object An Object describing an expected index
Source:
  • IDBWrapper/idbstore.js, line 640
Returns:
Whether both index definitions are identical
Type
Boolean

<static> iterate(onItem, options)

Iterates over the store using the given options and calling onItem for each entry matching the options.

Parameters:
Name Type Argument Description
onItem Function A callback to be called for each match
options Object <optional>
An object defining specific options
Properties
Name Type Argument Default Description
index Object <optional>
null An IDBIndex to operate on
order String <optional>
ASC The order in which to provide the results, can be 'DESC' or 'ASC'
filterDuplicates Boolean <optional>
false Whether to exclude duplicate matches
keyRange Object <optional>
null An IDBKeyRange to use
writeAccess Boolean <optional>
false Whether grant write access to the store in the onItem callback
onEnd Function <optional>
null A callback to be called after iteration has ended
onError Function <optional>
console.error A callback to be called if an error occurred during the operation.
Source:
  • IDBWrapper/idbstore.js, line 674

<static> makeKeyRange(options) → {Object}

Creates a key range using specified options. This key range can be handed over to the count() and iterate() methods. Note: You must provide at least one or both of "lower" or "upper" value.

Parameters:
Name Type Description
options Object The options for the key range to create
Properties
Name Type Argument Description
lower * <optional>
The lower bound
excludeLower Boolean <optional>
Whether to exclude the lower bound passed in options.lower from the key range
upper * <optional>
The upper bound
excludeUpper Boolean <optional>
Whether to exclude the upper bound passed in options.upper from the key range
Source:
  • IDBWrapper/idbstore.js, line 800
Returns:
The IDBKeyRange representing the specified options
Type
Object

<static> normalizeIndexData(indexData)

Normalizes an object containing index data and assures that all proprties are set.

Parameters:
Name Type Description
indexData Object The index data object to normalize
Properties
Name Type Argument Description
name String The name of the index
keyPath String <optional>
The key path of the index
unique Boolean <optional>
Whether the index is unique
multiEntry Boolean <optional>
Whether the index is multi entry
Source:
  • IDBWrapper/idbstore.js, line 627

<static> put(dataObj, onSuccess, onError)

Puts an object into the store. If an entry with the given id exists, it will be overwritten.

Parameters:
Name Type Argument Description
dataObj Object The object to store.
onSuccess Function <optional>
A callback that is called if insertion was successful.
onError Function <optional>
A callback that is called if insertion failed.
Source:
  • IDBWrapper/idbstore.js, line 377

<static> query(onSuccess, options)

Runs a query against the store and passes an array containing matched objects to the success handler.

Parameters:
Name Type Argument Description
onSuccess Function A callback to be called when the operation was successful.
options Object <optional>
An object defining specific query options
Properties
Name Type Argument Default Description
index Object <optional>
null An IDBIndex to operate on
order String <optional>
ASC The order in which to provide the results, can be 'DESC' or 'ASC'
filterDuplicates Boolean <optional>
false Whether to exclude duplicate matches
keyRange Object <optional>
null An IDBKeyRange to use
onError Function <optional>
console.error A callback to be called if an error occurred during the operation.
Source:
  • IDBWrapper/idbstore.js, line 731

<static> remove(key, onSuccess, onError)

Removes an object from the store.

Parameters:
Name Type Argument Description
key * The id of the object to remove.
onSuccess Function <optional>
A callback that is called if the removal was successful.
onError Function <optional>
A callback that will be called if an error occurred during the operation.
Source:
  • IDBWrapper/idbstore.js, line 425