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

Function buildConditionalSelect

packages/db/src/query/builder/index.ts:1056–1082  ·  view source on GitHub ↗
(
  wrapper: CaseWhenWrapper,
  parentAliases: Array<string>,
  fieldName?: string,
)

Source from the content-addressed store, hash-verified

1054}
1055
1056function buildConditionalSelect(
1057 wrapper: CaseWhenWrapper,
1058 parentAliases: Array<string>,
1059 fieldName?: string,
1060): ConditionalSelect {
1061 const args = wrapper.args
1062 if (args.length < 2) {
1063 throw new Error(`caseWhen() requires at least two arguments`)
1064 }
1065
1066 const hasDefaultValue = args.length % 2 === 1
1067 const pairCount = Math.floor(args.length / 2)
1068 const branches = []
1069
1070 for (let i = 0; i < pairCount; i++) {
1071 branches.push({
1072 condition: toExpression(args[i * 2]),
1073 value: buildNestedSelect(args[i * 2 + 1], parentAliases, fieldName),
1074 })
1075 }
1076
1077 const defaultValue = hasDefaultValue
1078 ? buildNestedSelect(args[args.length - 1], parentAliases, fieldName)
1079 : undefined
1080
1081 return new ConditionalSelect(branches, defaultValue)
1082}
1083
1084/**
1085 * Recursively collects all PropRef nodes from an expression tree.

Callers 1

buildNestedSelectFunction · 0.85

Calls 2

toExpressionFunction · 0.85
buildNestedSelectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…