Conditionals
Basic if
and else
if
and else
If you store the builder object in a variable, you can use if
and else
statements like you would expect.
This works, but breaks chainability. A better way is to use the when
helper method.
when
when
Name | Type | Required | Default | Description |
condition | boolean | true | The condition to switch on. | |
onTrue | Closure | true | The callback to execute if the condition is true. It is passed the | |
onFalse | Closure | false | function( q ) { return q; } | The callback to execute if the conditions is false. It is passed the |
We can rewrite the above query like so:
Nice. We keep chainability this way and reduce the number of temporary variables we need.
Last updated