Forked from webonix/lucee-member-functions-query-each.cfm
Created
June 3, 2018 16:30
-
-
Save ivanionut/70f5586d83e125c474e2e6f4719aefa6 to your computer and use it in GitHub Desktop.
query member function - each()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
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 | | |
*/ | |
ages = []; | |
people.each(function(row, rowNumber, qryData){ | |
ages.Append({'name': row.name, 'age': DateDiff('yyyy', row.dob, Now())}) | |
}); | |
dump(var=ages, label='calculated age'); | |
/* Output: | |
[ | |
{age:45,name:Susi}, | |
{age:20,name:Urs}, | |
{age:55,name:Fred}, | |
{age:27,name:Jim} | |
] | |
*/ | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment