caseMatch<T> method
Expression<T?>
caseMatch<T>({
- required Map<
Expression< when,D> , Expression<T?> > - Expression<
T?> ? orElse,
A CASE WHEN construct using the current expression as a base.
The expression on which caseMatch is invoked will be used as a base and
compared against the keys in when. If an equal key is found in the map,
the expression returned evaluates to the respective value.
If no matching keys are found in when, the orElse expression is
evaluated and returned. If no orElse expression is provided, NULL will
be returned instead.
For example, consider this expression mapping numerical weekdays to their name:
final weekday = myTable.createdOnWeekDay;
weekday.caseMatch<String>(
when: {
Constant(1): Constant('Monday'),
Constant(2): Constant('Tuesday'),
Constant(3): Constant('Wednesday'),
Constant(4): Constant('Thursday'),
Constant(5): Constant('Friday'),
Constant(6): Constant('Saturday'),
Constant(7): Constant('Sunday'),
},
orElse: Constant('(unknown)'),
);
Implementation
Expression<T?> caseMatch<T>({
required Map<Expression<D>, Expression<T?>> when,
Expression<T?>? orElse,
}) {
if (when.isEmpty) {
throw ArgumentError.value(when, 'when', 'Must not be empty');
}
return CaseWhenExpression<T>(this, when.entries.toList(), orElse);
}