QueryFilter

This function creates a new Query that returns all rows from an query that match the given filter.

Returns: query

Usage

QueryFilter( query, filter [, parallel [, maxThreads ] ] )

Arguments

Argument Description Default
query
(query, required)

query to filter entries from

filter
(function, required)

filter can be a function/closure that implements the following constructor [function(struct row[, number rowNumber, query query]):boolean].

parallel
(boolean, optional)

execute closures parallel

maxThreads
(number, optional)

maximum number of threads executed, ignored when argument "parallel" is set to false

20

Examples

people = QueryNew( "name,dob,age", "varchar,date,int", [
    [ "Susi", CreateDate( 1970, 1, 1 ), 0 ],
    [ "Urs" , CreateDate( 1995, 1, 1 ), 0 ],
    [ "Fred", CreateDate( 1960, 1, 1 ), 0 ],
    [ "Jim" , CreateDate( 1988, 1, 1 ), 0 ]
]);

Dump( var=people, label="people - origional query" );

/* Output:

| name | dob                 | age |
------------------------------------
| Susi | 1970-01-01 00:00:00 | 0   |
| Urs  | 1995-01-01 00:00:00 | 0   |
| Fred | 1960-01-01 00:00:00 | 0   |
| Jim  | 1988-01-01 00:00:00 | 0   |
*/

//filter - older than 21
qryPeopleOldEnough = people.filter(function(row, rowNumber, qryData){
    return DateDiff('yyyy', row.dob, Now()) > 21
});
dump(var=qryPeopleOldEnough, label='qryPeopleOldEnough - older than 21');

/* Output:

| name | dob                 | age |
------------------------------------
| Susi | 1970-01-01 00:00:00 | 0   |
| Fred | 1960-01-01 00:00:00 | 0   |
| Jim  | 1988-01-01 00:00:00 | 0   |
*/

See also