Expressions
Expressions are used within attributes and other constructs to define conditions, default values, etc.
Expressions support logical and comparison operations:
@where
,@permission
and@set
operators:==
,!=
,>
,<
,>=
,<=
,in
,!
,&&
,||
,=
@computed
operators: Same as above with the addition of+
,-
,*
,/
@computed
aggregate functions: see list below- Values: Literals (
true
,false
,null
, numbers, strings), identifiers, arrays. - Parentheses: Used for grouping, e.g.,
(a == b) and (c > d)
@computed
aggregate functions
SUM
Adds up all numeric values in a collection.
Syntax: SUM(items)
Example usage:
@computed(SUM(customer.orders.total))
COUNT
Counts the number of items in a collection.
Syntax: COUNT(items)
Example usage:
@computed(COUNT(customer.orders))
AVG
Computes the arithmetic average of numeric values in a collection.
Syntax: AVG(items)
Example usage:
@computed(AVG(invoice.items.total))
MEDIAN
Computes the arithmetic median of the numeric values in a collection.
Syntax: MEDIAN(items)
Example usage:
@computed(MEDIAN(invoice.items.total))
MIN
Finds the smallest numeric value in a collection.
Syntax: MIN(items)
Example usage:
@computed(MEDIAN(invoice.items.total))
MAX
Finds the largest numeric value in a collection.
Syntax: MAX(items)
Example usage:
@computed(MEDIAN(invoice.items.total))
SUMIF
Adds up numeric values that satisfy a given condition.
Syntax: SUMIF(items, condition)
Example usage:
@computed(SUMIF(invoice.items.product.price, !invoice.items.isDiscounted))
COUNTIF
Counts items that satisfy a given condition.
Syntax: COUNTIF(items, condition)
Example usage:
@computed(SUMIF(invoice.items.product.price, invoice.items.isDiscounted))
AVGIF
Computes the average of numeric values that satisfy a given condition.
Syntax: AVGIF(items, condition)
Example usage:
@computed(SUMIF(customer.orders.total, customer.orders.isShipped))
MEDIANIF
Finds the median of numeric values that satisfy a given condition.
Syntax: MEDIANIF(items, condition)
Example usage:
@computed(SUMIF(customer.orders.total, customer.orders.isShipped))
MINIF
Finds the smallest numeric value that satisfies a given condition.
Syntax: MINIF(items, condition)
Example usage:
@computed(MINIF(invoice.items.total, !invoice.items.isDeleted && invoice.items.price > 0))
MAXIF
Finds the largest numeric value that satisfies a given condition.
Syntax: MAXIF(items, condition)
Example usage:
@computed(MAXIF(invoice.items.total, !invoice.items.isDeleted && invoice.items.price > 0))