new IndexedDB(storeName, settings) → {Object}
Status: Experimental
The IndexedDB adapter stores data in an IndexedDB database for more persistent client side storage
This constructor is instantiated when the "DataManager.add()" method is called
Parameters:
Name | Type | Argument | Default | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
storeName |
String | the name used to reference this particular store | ||||||||||||||||||||||||||||||||||
settings |
Object |
<optional> |
{} | the settings to be passed to the adapter
Properties
|
Returns:
The created store
- Type
- Object
Example
// Create an empty DataManager
var dm = AeroGear.DataManager();
// Add an IndexedDB store
dm.add({
name: "newStore",
type: "IndexedDB"
});
Methods
-
<static> isValid()
-
Determine if this adapter is supported in the current environment
-
close()
-
Close the current store
Example
// Create an empty DataManager var dm = AeroGear.DataManager(); // Add an IndexedDB store and then delete a record dm.add({ name: "newStore", type: "IndexedDB" }); dm.stores.newStore.close();
-
filter(filterParameters, matchAny) → {Object}
-
Filter the current store's data
Parameters:
Name Type Argument Description filterParameters
Object <optional>
An object containing key/value pairs on which to filter the store's data. To filter a single parameter on multiple values, the value can be an object containing a data key with an Array of values to filter on and its own matchAny key that will override the global matchAny for that specific filter parameter. matchAny
Boolean <optional>
When true, an item is included in the output if any of the filter parameters is matched. Returns:
A Promise- Type
- Object
Example
// Create an empty DataManager var dm = AeroGear.DataManager(); // Add an IndexedDB store dm.add({ name: "newStore", type: "IndexedDB" }); dm.stores.newStore.open() .then( function() { dm.stores.test1.filter( { "name": "Lucas" }, true ) .then( function( filteredData ) { ... } ) .catch( function( error ) { ... } ); });
-
open() → {Object}
-
Open the Database
Returns:
A Promise- Type
- Object
Example
// Create an empty DataManager var dm = AeroGear.DataManager(); // Add an IndexedDB store dm.add({ name: "newStore", type: "IndexedDB" }); dm.stores.newStore.open() .then(function() { ... }) .catch(function(error) { ... });
-
read(id) → {Object}
-
Read data from a store
Parameters:
Name Type Argument Description id
String | Number <optional>
Usually a String or Number representing a single "record" in the data set or if no id is specified, all data is returned Returns:
A Promise- Type
- Object
Example
// Create an empty DataManager var dm = AeroGear.DataManager(); // Add an IndexedDB store dm.add({ name: "newStore", type: "IndexedDB" }); dm.stores.newStore.open() .then( function() { // read all records dm.stores.test1.read( undefined ) .then( function( data ) { ... } ) .catch( function( error ) { ... } ); // read a record with a particular id dm.stores.test1.read( 5 ) .then( function( data ) { ... } ) .catch( function( error ) { ... } ); });
-
remove(toRemove) → {Object}
-
Removes data from the store
Parameters:
Name Type Description toRemove
String | Object | Array A variety of objects can be passed to remove to specify the item or if nothing is provided, all data is removed Returns:
A Promise- Type
- Object
Example
// Create an empty DataManager var dm = AeroGear.DataManager(); // Add an IndexedDB store dm.add({ name: "newStore", type: "IndexedDB" }); dm.stores.newStore.open() .then( function() { // remove one record dm.stores.newStore.remove( 1 ) .then( function( newData ) { ... } ) .catch( function( error ) { ... } ); // save multiple Records dm.stores.newStore.remove( undefined ) .then( function( newData ) { ... } ) .catch( function( error ) { ... } ); });
-
save(data, options) → {Object}
-
Saves data to the store, optionally clearing and resetting the data
Parameters:
Name Type Argument Default Description data
Object | Array An object or array of objects representing the data to be saved to the server. When doing an update, one of the key/value pairs in the object to update must be the `recordId` you set during creation of the store representing the unique identifier for a "record" in the data set. options
Object <optional>
{} additional options Properties
Name Type Argument Description reset
Boolean <optional>
If true, this will empty the current data and set it to the data being saved Returns:
A Promise- Type
- Object
Example
// Create an empty DataManager var dm = AeroGear.DataManager(); // Add an IndexedDB store dm.add({ name: "newStore", type: "IndexedDB" }); dm.stores.newStore.open() .then( function() { // save one record dm.stores.newStore.save( { "id": 3, "name": "Grace", "type": "Little Person" }) .then( function( newData ) { ... } ) .catch( function( error ) { ... } ); // save multiple Records dm.stores.newStore.save([ { "id": 3, "name": "Grace", "type": "Little Person" }, { "id": 4, "name": "Graeham", "type": "Really Little Person" } ]) .then( function( newData ) { ... } ) .catch( function( error ) { ... } ); });