Constructor
new DatabaseCollection(objectStoreName, Model, database)
Create a new Collection
- Source:
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
storeName
Returns the name of the object store for this collection.
- Source:
Methods
add(dataopt) → {Promise.<(Object|Array)>}
Add an item to the database.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Object
|
Array
|
<optional> |
[] |
The data to add. |
Returns:
- Type:
-
Promise.<(Object|Array)>
Returns a Promise that resolves to the new database item or an array of the new database items.
delete(clientIDs) → {Promise}
Delete the item or items with the specified client ID(s) (cid(s)) by adding a "deleted" flag to the item.
- Source:
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) → {Promise.<(Object|null)>}
Retrieve an item from the database by client ID (cid), or an IndexedDB key range.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
key |
String
|
IDBKeyRange
|
The client ID (cid) of the item, or an IDBKeyRange. |
Returns:
- Type:
-
Promise.<(Object|null)>
Returns a Promise that resolves to the retrieved item, or null if not found.
getAll(optionsopt) → {Promise.<Array>}
Retrieve all the items from the collection.
- Source:
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
<optional> |
{} |
|
Returns:
- Type:
-
Promise.<Array>
Returns a Promise that resolves to an Array of items in the collection.
iterate(cb, optionsopt) → {Promise}
Run a callback for each item in the collection. Useful for retrieving very large collections asynchronously.
- Source:
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cb |
function
|
The callback function to call on each returned item. |
||||||||||||||||||
options |
Object
|
<optional> |
{} |
Options
|
Returns:
- Type:
-
Promise
put(dataopt) → {Promise}
Add or update one or more items to the collection.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Object
|
Array
|
<optional> |
[] |
An object or array of objects to add to the collection. |
Returns:
- Type:
-
Promise
Returns the new object or an array of new objects, with client IDs (cid).