MCPcopy Create free account
hub / github.com/effect-app/libs / aggregateSelectExpr

Function aggregateSelectExpr

packages/infra/src/Store/SQL/query.ts:506–524  ·  view source on GitHub ↗
(key: string, agg: AggregateIrExpression)

Source from the content-addressed store, hash-verified

504 }
505
506 const aggregateSelectExpr = (key: string, agg: AggregateIrExpression): string => {
507 switch (agg._tag) {
508 case "agg-count":
509 return `COUNT(1) AS "${key}"`
510 case "agg-count-when": {
511 if (agg.filter.length === 0) return `COUNT(1) AS "${key}"`
512 const cond = print([{ t: "where-scope", result: agg.filter, relation: "some" }], null, false)
513 return `COUNT(CASE WHEN ${cond} THEN 1 END) AS "${key}"`
514 }
515 case "agg-sum":
516 return `COALESCE(SUM(${fieldExpr(agg.field)}), 0) AS "${key}"`
517 case "agg-min":
518 return `MIN(${fieldExpr(agg.field)}) AS "${key}"`
519 case "agg-max":
520 return `MAX(${fieldExpr(agg.field)}) AS "${key}"`
521 default:
522 return assertUnreachable(agg)
523 }
524 }
525
526 const hasAggregates = select
527 ? select.some((s) => typeof s === "object" && s !== null && "aggregate" in s)

Callers 1

getSelectExprFunction · 0.70

Calls 3

assertUnreachableFunction · 0.90
fieldExprFunction · 0.85
printFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…