dojo/store/util/SimpleQueryEngine

Summary

Simple query engine that matches using filter functions, named filter functions or objects by name-value on a query object hash

The SimpleQueryEngine provides a way of getting a QueryResults through the use of a simple object hash as a filter. The hash will be used to match properties on data objects with the corresponding value given. In other words, only exact matches will be returned.

This function can be used as a template for more complex query engines; for example, an engine can be created that accepts an object hash that contains filtering functions, or a string that gets evaluated, etc.

When creating a new dojo.store, simply set the store's queryEngine field as a reference to this function.

Usage

SimpleQueryEngine(query,options);
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.

See the dojo/store/util/SimpleQueryEngine reference documentation for more information.

Examples

Example 1

Define a store with a reference to this engine, and set up a query method.

var myStore = function(options){
    //  ...more properties here
    this.queryEngine = SimpleQueryEngine;
    //  define our query method
    this.query = function(query, options){
        return QueryResults(this.queryEngine(query, options)(this.data));
    };
};

Methods

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