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

Function caseWhen

packages/db/src/query/builder/functions.ts:578–599  ·  view source on GitHub ↗
(...args: Array<CaseWhenValue>)

Source from the content-addressed store, hash-verified

576 ...rest: Array<CaseWhenValue>
577): any
578export function caseWhen(...args: Array<CaseWhenValue>): any {
579 if (args.length < 2) {
580 throw new Error(`caseWhen() requires at least two arguments`)
581 }
582
583 const pairCount = Math.floor(args.length / 2)
584 for (let i = 0; i < pairCount; i++) {
585 const condition = args[i * 2]
586 if (!isConditionValue(condition)) {
587 throw new Error(`caseWhen() conditions must be expression-like values`)
588 }
589 }
590
591 if (caseWhenHasOnlyExpressionValues(args)) {
592 return new Func(
593 `caseWhen`,
594 args.map((arg) => toExpression(arg)),
595 )
596 }
597
598 return new CaseWhenWrapper(args)
599}
600
601export function add<T1 extends ExpressionLike, T2 extends ExpressionLike>(
602 left: T1,

Callers 4

union-all.test.tsFile · 0.85
createGroupByTestsFunction · 0.85
case-when.test.tsFile · 0.85

Calls 4

isConditionValueFunction · 0.85
toExpressionFunction · 0.85
mapMethod · 0.45

Tested by 1

createGroupByTestsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…