MCPcopy Index your code
hub / github.com/TanStack/db / compileConditionalSelect

Function compileConditionalSelect

packages/db/src/query/compiler/select.ts:227–248  ·  view source on GitHub ↗
(
  conditional: ConditionalSelect,
)

Source from the content-addressed store, hash-verified

225}
226
227function 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

Callers 2

compileSelectValueFunction · 0.85
addFromObjectFunction · 0.85

Calls 4

compileSelectValueFunction · 0.85
isCaseWhenConditionTrueFunction · 0.85
compileExpressionFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected