dojo/store/Memory

Summary

This is a basic in-memory object store. It implements dojo/store/api/Store.

Usage

var foo = new Memory(options);

dojo/store/Memory

Parameter Type Description
options dojo/store/Memory

This provides any configuration information that will be mixed into the store. This should generally include the data property to provide the starting set of data.

See the dojo/store/Memory reference documentation for more information.

Properties

data

Defined by: dojo/store/Memory

The array of all the objects in the memory store

idProperty

Defined by: dojo/store/Memory

Indicates the property to use as the identity property. The values of this property should be unique.

index

Defined by: dojo/store/Memory

An index of data indices into the data array by id

Methods

add(object,options)

Defined by dojo/store/Memory

Creates an object, throws an error if the object already exists

Parameter Type Description
object Object

The object to store.

options dojo/store/api/Store.PutDirectives
Optional

Additional metadata for storing the data. Includes an "id" property if a specific id is to be used.

Returns: Number | undefined

get(id)

Defined by dojo/store/Memory

Retrieves an object by its identity

Parameter Type Description
id Number

The identity to use to lookup the object

Returns: Object | undefined

The object in the store that matches the given id.

getChildren(parent,options)

Defined by dojo/store/api/Store

Retrieves the children of an object.

Parameter Type Description
parent Object

The object to find the children of.

options dojo/store/api/Store.QueryOptions
Optional

Additional options to apply to the retrieval of the children.

Returns: dojo/store/api/Store.QueryResults

A result set of the children of the parent object.

getIdentity(object)

Defined by dojo/store/Memory

Returns an object's identity

Parameter Type Description
object Object

The object to get the identity from

Returns: Number | undefined

getMetadata(object)

Defined by dojo/store/api/Store

Returns any metadata about the object. This may include attribution, cache directives, history, or version information.

Parameter Type Description
object Object

The object to return metadata for.

Returns: Object

An object containing metadata.

put(object,options)

Defined by dojo/store/Memory

Stores an object

Parameter Type Description
object Object

The object to store.

options dojo/store/api/Store.PutDirectives
Optional

Additional metadata for storing the data. Includes an "id" property if a specific id is to be used.

Returns: Number | undefined

query(query,options)

Defined by dojo/store/Memory

Queries the store for objects.

Parameter Type Description
query Object

The query to use for retrieving objects from the store.

options dojo/store/api/Store.QueryOptions
Optional

The optional arguments to apply to the resultset.

Returns: dojo/store/api/Store.QueryResults | undefined

The results of the query, extended with iterative methods.

Examples

Example 1

Given the following store:

var store = new Memory({
    data: [
        {id: 1, name: "one", prime: false },
        {id: 2, name: "two", even: true, prime: true},
        {id: 3, name: "three", prime: true},
        {id: 4, name: "four", even: true, prime: false},
        {id: 5, name: "five", prime: true}
    ]
});

...find all items where "prime" is true:

var results = store.query({ prime: true });

...or find all items where "even" is true:

var results = store.query({ even: true });

queryEngine(query,options)

Defined by dojo/store/Memory

Defines the query engine to use for querying the data store

Parameter Type Description
query Object

An object hash with fields that may match fields of items in the store. Values in the hash will be compared by normal == operator, but regular expressions or any object that provides a test() method are also supported and can be used to match strings by more complex expressions (and then the regex's or object's test() method will be used to match values).

options dojo/store/api/Store.QueryOptions
Optional

An object that contains optional information such as sort, start, and count.

Returns: Function | function

A function that caches the passed query under the field "matches". See any of the "query" methods on dojo.stores.

remove(id)

Defined by dojo/store/Memory

Deletes an object by its identity

Parameter Type Description
id Number

The identity to use to delete the object

Returns: Boolean | boolean

Returns true if an object was removed, falsy (undefined) if no object matched the id

setData(data)

Defined by dojo/store/Memory

Sets the given data as the source for this store, and indexes it

Parameter Type Description
data Object[]

An array of objects to use as the source of data.

transaction()

Defined by dojo/store/api/Store

Starts a new transaction. Note that a store user might not call transaction() prior to using put, delete, etc. in which case these operations effectively could be thought of as "auto-commit" style actions.

Returns: dojo/store/api/Store.Transaction

This represents the new current transaction.

© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/store/Memory.html