Class: Collection

Collection

A utility class for performing operations on an IndexedDB object store


new Collection(objectStoreName, Model, database)

Create a new Collection

Parameters:
Name Type Description
objectStoreName String

The name of the object store to use for the collection

Model function

An ES6 class. Items in this collection will be instances of this model.

database IDBDatabase

The instance of the IndexedDB database to create transactions on.

Members


idb :IDBDatabase

A reference to the IndexedDB database instance

Type:
  • IDBDatabase

Model :function

The class that serves as the model for each instance in this collection.

Type:
  • function

storeName :String

The name of the object store that this collection corresponds to.

Type:
  • String

Methods


add( [data])

Adds an item to the database

Parameters:
Name Type Argument Default Description
data Object | Array <optional>
[]

The data to add.

Returns:

Returns a Promise that resolves to the new database item or an array of the new database items.

Type
Promise

delete(clientIDs)

Deletes the item with the specified client ID (cid) by adding a "deleted" flag to the item.

Parameters:
Name Type Description
clientIDs String | Array

A client ID (cid) or Array of client IDs of the item(s) to delete

Returns:
Type
Promise

get(key)

Retrieves an item from the database by client ID (cid), or an IndexedDB key range

Parameters:
Name Type Description
key String | IDBKeyRange

The client ID (cid) of the item, or an IDBKeyRange

Returns:

Returns a Promise that resolves to the retrieved item, or null if not found

Type
Promise

getAll(query, count)

Retrieves all the items from the collection

Parameters:
Name Type Description
query String | IDBKeyRange

The client ID (cid) or an IDBKeyRange to limit the results to.

count Integer

The number of items to return if more than 1 is found.

Returns:

Returns a Promise that resolves to an Array of items in the collection

Type
Promise

put( [data])

Adds one or more items to the collection

Parameters:
Name Type Argument Default Description
data Object | Array <optional>
[]

An object or array of objects to add to the collection

Returns:

Returns an array of new objects, with client IDs (cid)

Type
Promise