Adapter: Memory

AeroGear.DataManager.adapters. Memory

new Memory(storeName, settings) → {Object}

Status: Stable
The Memory adapter is the default type used when creating a new store. Data is simply stored in a data var and is lost on unload (close window, leave page, etc.) 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
Source:
Returns:
The created store
Type
Object
Example
// Create an empty DataManager
var dm = AeroGear.DataManager();

// Add a custom memory store
dm.add( "newStore", {
    recordId: "customID"
});

Methods

<static> isValid()

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

filter(filterParameters, matchAny, options) → {Object}

Filter the current store's data
Parameters:
Name Type Argument Default 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.
options Object <optional>
{} options
Properties
Name Type Argument Description
success AeroGear~successCallbackMEMORY <optional>
a callback to be called after successfully filter data from a Memory Store - this filter is synchronous but the callback is provided for API symmetry.
Source:
Returns:
A jQuery.Deferred promise
Type
Object
Example
var dm = AeroGear.DataManager( "tasks" ).stores[ 0 ];

// An object can be passed to filter the data
// This would return all records with a user named 'admin' **AND** a date of '2012-08-01'
dm.stores.tasks.filter({
        date: "2012-08-01",
        user: "admin"
    },
    {
        success: function( data ) { ... },
        error: function( error ) { ... }
    }
);

// The matchAny parameter changes the search to an OR operation
// This would return all records with a user named 'admin' **OR** a date of '2012-08-01'
dm.stores.tasks.filter({
        date: "2012-08-01",
        user: "admin"
    },
    true,
    {
        success: function( data ) { ... },
        error: function( error ) { ... }
    }
);

read(id, options) → {Object}

Read data from a store
Parameters:
Name Type Argument Default 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
options Object <optional>
{} options
Properties
Name Type Argument Description
success AeroGear~successCallbackMEMORY <optional>
a callback to be called after successfully reading a Memory Store - this read is synchronous but the callback is provided for API symmetry.
Source:
Returns:
A jQuery.Deferred promise
Type
Object
Example
var dm = AeroGear.DataManager( "tasks" ).stores[ 0 ];

// Get an array of all data in the store
dm.read()
    .then( function( data ) {
        console.log( data );
    });

// Read a specific piece of data based on an id
dm.read( 12345 )
    .then( function( data ) {
        console.log( data );
    });

remove(toRemove, options) → {Object}

Removes data from the store
Parameters:
Name Type Argument Default 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
options Object <optional>
{} options
Properties
Name Type Argument Description
success AeroGear~successCallbackMEMORY <optional>
a callback to be called after successfully removing data from a Memory Store - this remove is synchronous but the callback is provided for API symmetry.
Source:
Returns:
A jQuery.Deferred promise
Type
Object
Example
var dm = AeroGear.DataManager( "tasks" ).stores[ 0 ];

// Store a new task
dm.save({
    title: "Created Task"
});

// Store another new task
dm.save({
    title: "Another Created Task"
});

// Store one more new task
dm.save({
    title: "And Another Created Task"
});

// Delete a record
dm.remove( 1, {
    success: function( data ) { ... },
    error: function( error ) { ... }
});

// Remove all data
dm.remove( undefined, {
    success: function( data ) { ... },
    error: function( error ) { ... }
});

// Delete all remaining data from the store
dm.remove();

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>
{} 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
success AeroGear~successCallbackMEMORY <optional>
a callback to be called after successfully saving data from a Memory Store - this save is synchronous but the callback is provided for API symmetry.
Source:
Returns:
A jQuery.Deferred promise
Type
Object
Example
var dm = AeroGear.DataManager( "tasks" ).stores[ 0 ];

// Store a new task
dm.save({
    title: "Created Task",
    date: "2012-07-13",
    ...
});

// Store an array of new Tasks
dm.save([
    {
        title: "Task2",
        date: "2012-07-13"
    },
    {
        title: "Task3",
        date: "2012-07-13"
        ...
    }
]);

// Update an existing piece of data
var toUpdate = dm.read()[ 0 ];
toUpdate.data.title = "Updated Task";
dm.save( toUpdate );