Spec-Zone.ru › ColdFusion

queryFilter

Filters query rows specified in filter criteria

queryFilter(query, function(row [, currentRow] [, query] ){} [, parallel] [, maxThreads]) → returns query

Member Function Syntax

query.filter(function(row [, currentRow] [, query] ){} [, parallel] [, maxThreads])

  • CF2016+
  • Lucee
  • BL 1.0.0+
  • See Also: querySome queryReduce queryMap queryEach

    Argument Reference

    query query
    Required

    The query to filter

    callback boolean
    Required

    Closure or a function reference that will be called for each of the iteration. Returns true if the row should be included in the filtered query.

    Callback parameters:

    • row* struct : A struct with all of the columns for the current iteration
    • currentRow* numeric : The row number for the current iteration
    • query* query : A reference of the original query

    parallel boolean
    Default: false

    Lucee 4.5+ CF 2021+ true if the items can be executed in parallel
    Values:
    • true
    • false

    maxThreads numeric
    Default: 20

    Lucee 4.5+ CF 2021+ the maximum number of threads to use when parallel = true

    Compatibility

    ColdFusion:

    Version 2016+ queryFilter mutated the original query in CF2016 and 2018 (bug report: https://tracker.adobe.com/#/view/CF-4203366)

    Links more information about queryFilter

    • Map, Reduce and other Higher Order Functions - A Primer for map, reduce, filter, and Higher Order Functions in general.
    • ColdFusion 2016: query iteration functions - A look at the higher-order functions that queries have

    Examples
    Sample code invoking the queryFilter function

    Filter a query

    news = queryNew("id,type,title", "integer,varchar,varchar");
        queryAddRow(news,[{
            id: 1,
            type: "book",
            title: "Cloud Atlas"
        },{
            id: 2,
            type: "book",
            title: "Lord of The Rings"
        },{
            id: 3,
            type: "film",
            title: "Men in Black"
        }]);
        books = queryFilter(news,function(_news) {
            return _news.type is 'book';
        });
        writeDump(valueList(books.title,', '));

    Expected Result: Cloud Atlas, Lord of The Rings

    Filter a query as member function

    news = queryNew("id,type,title", "integer,varchar,varchar");
        queryAddRow(news,[{
            id: 1,
            type: "book",
            title: "Cloud Atlas"
        },{
            id: 2,
            type: "book",
            title: "Lord of The Rings"
        },{
            id: 3,
            type: "film",
            title: "Men in Black"
        }]);
        books = news.filter(function(_news) {
            return _news.type is 'book';
        });
        writeDump(valueList(books.title,', '));

    Expected Result: Cloud Atlas, Lord of The Rings

    © 2012–present Foundeo, Inc. and the CFDocs contributors.
    Licensed under the MIT License.
    ColdFusion is a trademark of Adobe Systems Incorporated.
    https://cfdocs.org/queryfilter

    Spec-Zone.ru

    Настройки Оффлайн Что нового Помощь О нас
    Spec-Zone .ru
    спецификации, руководства, описания, API