MCPcopy Create free account
hub / github.com/TanStack/db / replaceGroupByRefsInExpression

Function replaceGroupByRefsInExpression

packages/db/src/query/compiler/group-by.ts:826–849  ·  view source on GitHub ↗
(
  expr: BasicExpression,
  groupByClause: GroupBy,
)

Source from the content-addressed store, hash-verified

824}
825
826function replaceGroupByRefsInExpression(
827 expr: BasicExpression,
828 groupByClause: GroupBy,
829): BasicExpression {
830 if (expr.type === `ref`) {
831 const groupIndex = groupByClause.findIndex((groupExpr) =>
832 expressionsEqual(expr, groupExpr),
833 )
834 return groupIndex === -1
835 ? expr
836 : new PropRef([`$selected`, `${GROUP_KEY_REF_PREFIX}${groupIndex}`])
837 }
838
839 if (expr.type === `func`) {
840 return new Func(
841 expr.name,
842 expr.args.map((arg) =>
843 replaceGroupByRefsInExpression(arg, groupByClause),
844 ),
845 )
846 }
847
848 return expr
849}
850
851function compileGroupedSelectValue(
852 value: SelectValueExpression,

Callers 1

Calls 2

expressionsEqualFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected