queryMap

Maps each query row using a function to manipulate the rows fields

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

Member Function Syntax

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

Argument Reference

query query
Required

query to process entries from

callback boolean
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
Default: false

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

maxThreads numeric
Default: 20

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

Links more information about queryMap

Examples
Sample code invoking the queryMap function

Manipulates query column

news = queryNew("id,title",
	"integer,varchar", [{
		"id": 1,
		"title": "Dewey defeats Truman"
	}, {
		"id": 2,
		"title": "Man walks on Moon"
	}]
);

writeDump(news);

function mapQuery(any Obj) {
	if (Obj.id == 1)
		Obj.title = "NEW: " & Obj.title;
	return Obj;
}

newQuery = QueryMap(news, mapQuery);
writeDump(newQuery);

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub