
Iterating a collection of entities or primitives can be done using a for loop. There are three types of for loop statements:
This type of for loop iterates the collection produced by expression e, which must contain elements of type t. The elements in the collection are accessible through identifier id.
The collection can be filtered:
for(id:t in e){ stat* }
for(id:t in e filter){ stat* }
This for loop iterates all the entities in the database of type t. These can also be filtered. Note that it is more efficient to retrieve the objects using a filtering query and use the regular for loop above for iteration.
for(id:t){ stat* }
for(id:t filter){ stat* }
This for loop iterates the numbers from e1 to e2-1.
for(id:Int from e1 to e2){ stat* }
The filter part of a for loop can consist of four parts:
where e1
e1 is a boolean expression which needs to evaluate to true for the element to be iterated.
order by e2 asc/desc
e2 is an expression that needs to produce a primitive type such as String or Int, which will be used to order the elements ascending or descending.
limit e3
e3 is an Int expression which will limit the number of elements that get iterated.
offset e4
e4 is an Int expression which will offset the starting element of the iteration.
Each of the four parts is optional, but they have to be specified in this order. The filtering is done in the application, so use queries instead of filters to optimize the WebDSL application.