( conditional: ConditionalSelect, )
| 225 | } |
| 226 | |
| 227 | function compileConditionalSelect( |
| 228 | conditional: ConditionalSelect, |
| 229 | ): (row: NamespacedRow) => any { |
| 230 | const branches = conditional.branches.map((branch) => ({ |
| 231 | condition: compileExpression(branch.condition), |
| 232 | value: compileSelectValue(branch.value), |
| 233 | })) |
| 234 | const defaultFn = |
| 235 | conditional.defaultValue === undefined |
| 236 | ? undefined |
| 237 | : compileSelectValue(conditional.defaultValue) |
| 238 | |
| 239 | return (row) => { |
| 240 | for (const branch of branches) { |
| 241 | if (isCaseWhenConditionTrue(branch.condition(row))) { |
| 242 | return branch.value(row) |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | return defaultFn !== undefined ? defaultFn(row) : null |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Helper function to check if an expression is an aggregate |
no test coverage detected