Spec-Zone.ru › ColdFusion

queryEach

Iterates over query rows and passes each row per iteration to a callback function

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

Member Function Syntax

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

  • CF2016+
  • Lucee
  • BL 1.0.0+
  • See Also: QueryMap QueryReduce QueryFilter

    Argument Reference

    query query
    Required

    query to loop over

    callback any
    Required

    Closure or a function reference that will be called for each of the iteration.

    Callback parameters:

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

    parallel boolean

    Lucee 4.5+ Executes closures parallel

    maxThreads numeric
    Default: 20

    Lucee 4.5+ Maximum number of threads executedIf parallel argument is set to false it will be ignored

    Compatibility

    Lucee:

    When called as a member function query.each() is chainable.

    Links more information about queryEach

    • 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 queryEach function

    Iterate over query rows instead of cfloop()

    ACF 2016+ and Lucee 5+

    <cfscript>
        news = queryNew("id,title",
        	"integer,varchar", [{
        		"id": 1,
        		"title": "Dewey defeats Truman"
        	}, {
        		"id": 2,
        		"title": "Man walks on Moon"
        	}]
        );
        function newsRow(row) {
            writeOutput("<tr>");
                writeOutput("<td>#row.id#</td>");
                writeOutput("<td>#row.title#</td>");
            writeOutput("</tr>");
        }
    </cfscript>
    <table>
        <cfscript>
            queryEach(news,newsRow);
        </cfscript>
    </table>

    Expected Result: 1 Dewey defeats Truman 2 Man walks on Moon

    Iterate over query rows instead of cfloop()

    Lucee 5+

    <cfscript>
        news = queryNew("id,title",
        	"integer,varchar", [{
        		"id": 1,
        		"title": "Dewey defeats Truman"
        	}, {
        		"id": 2,
        		"title": "Man walks on Moon"
        	}]
        );
        function newsRow(row) {
            writeOutput("<tr>");
                writeOutput("<td>#row.id#</td>");
                writeOutput("<td>#row.title#</td>");
            writeOutput("</tr>");
        }
    </cfscript>
    <table>
        <cfoutput>#queryEach(news,newsRow)#</cfoutput>
    </table>

    Expected Result: 1 Dewey defeats Truman 2 Man walks on Moon

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

    Spec-Zone.ru

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