caseMatch<T extends Object> method

Expression<T> caseMatch<T extends Object>({
  1. required Map<Expression<D>, Expression<T>> when,
  2. 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;
  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)'),


Expression<T> caseMatch<T extends Object>({
  required Map<Expression<D>, Expression<T>> when,
  Expression<T>? orElse,
}) {
  return CaseWhenExpressionWithBase<D, T>(
    cases: => CaseWhen(e.key, then: e.value)),
    orElse: orElse,