Adapter: WebSQL

AeroGear.DataManager.adapters. WebSQL

new WebSQL(storeName, settings) → {Object}

Status: Experimental
The WebSQL adapter stores data in a WebSQL 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
Name Type Argument Default Description
recordId String <optional>
"id" the name of the field used to uniquely identify a "record" in the data
auto Boolean <optional>
true set to 'false' to disable 'auto-connect' for read/remove/save/filter
crypto Object <optional>
the crypto settings to be passed to the adapter
Properties
Name Type Argument Description
agcrypto Object <optional>
the AeroGear.Crypto object to be used
options Object <optional>
the specific options for the AeroGear.Crypto encrypt/decrypt methods
Source:
Returns:
The created store
Type
Object
Example
    // Create an empty DataManager
    var dm = AeroGear.DataManager();

    // Add an WebSQL store
    dm.add({
        name: "newStore",
        type: "WebSQL"
    });

Methods

<static> isValid()

Determine if this adapter is supported in the current environment
Source:

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.
Source:
Returns:
A Promise
Type
Object
Example
    // Create an empty DataManager
    var dm = AeroGear.DataManager();

    // Add an IndexedDB store
    dm.add({
        name: "newStore",
        type: "WebSQL"
    });

    dm.stores.newStore.open()
        .then( function() {

        dm.stores.test1.filter( { "name": "Lucas" }, true )
            .then( function( filteredData ) { ... } )
            .catch( function( error ) { ... } );
    });

open() → {Object}

Open the Database
Source:
Returns:
A Promise
Type
Object
Example
    // Create an empty DataManager
    var dm = AeroGear.DataManager();

    // Add an WebSQL store
    dm.add({
        name: "newStore",
        type: "WebSQL"
    });

    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
Source:
Returns:
A Promise
Type
Object
Example
    // Create an empty DataManager
    var dm = AeroGear.DataManager();

    // Add an WebSQL store
    dm.add({
        name: "newStore",
        type: "WebSQL"
    });

    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
Source:
Returns:
A Promise
Type
Object
Example
    // Create an empty DataManager
    var dm = AeroGear.DataManager();

    // Add an IndexedDB store
    dm.add({
        name: "newStore",
        type: "WebSQL"
    });

    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
Source:
Returns:
A Promise
Type
Object
Example
    // Create an empty DataManager
    var dm = AeroGear.DataManager();

    // Add an WebSQL store
    dm.add({
        name: "newStore",
        type: "WebSQL"
    });

    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 ) { ... } );
    });