Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#14679 closed enhancement (fixed)

Add the ability to use functions in queries for SimpleQueryEngine

Reported by: Tom Trenka Owned by: kriszyp
Priority: high Milestone: 1.8
Component: Data Version: 1.7.1
Keywords: SimpleQueryEngine Cc:
Blocked By: Blocking:

Description

I recently had a need to be able to use comparison functions in a query for various (mostly Memory) stores...to do this, I made the following mod in SimpleQueryEngine?.js, starting at line 55 (of 1.7):

case "object": case "undefined":
	var queryObject = query;
	query = function(object){
		for(var key in queryObject){
			var required = queryObject[key];
			if(required && required.test){
				if(!required.test(object[key])){
					return false;
				}
			} else if(typeof(required) == "function"){
				if(!required(object[key], object)){
					return false;
				}
			} else if(required != object[key]){
				return false;
			}
		}
		return true;
	};
	break;

The idea is that you can use a function of the signature (object[key], object) to return a value (probably boolean). So you could have a store with an object set that has the following signature:

{ order, name, description, foo }

...and then do a query against it like so:

query = { name: /^A*/, order: function(data, obj){ return data < obj.foo } };

Change History (2)

comment:1 Changed 8 years ago by Kris Zyp

Resolution: fixed
Status: newclosed

Fixed with [27679], not sure why it isn't showing up.

comment:2 Changed 8 years ago by bill

Component: GeneralData
Note: See TracTickets for help on using tickets.