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

Function aggregateSelectExpr

packages/infra/src/Store/Cosmos/query.ts:313–338  ·  view source on GitHub ↗
(key: string, agg: AggregateIrExpression)

Source from the content-addressed store, hash-verified

311 : false
312
313 const aggregateSelectExpr = (key: string, agg: AggregateIrExpression): string => {
314 switch (agg._tag) {
315 case "agg-count":
316 return `COUNT(1) AS ${key}`
317 case "agg-count-when": {
318 if (agg.filter.length === 0) return `COUNT(1) AS ${key}`
319 const cond = print(agg.filter, null, false)
320 // Cosmos supports SUM(IIF(cond, 1, 0)) as a conditional count
321 return `SUM(IIF(${cond}, 1, 0)) AS ${key}`
322 }
323 case "agg-sum": {
324 const fieldRef = dottedToAccess(`f.${agg.field}`)
325 return `SUM(${fieldRef}) AS ${key}`
326 }
327 case "agg-min": {
328 const fieldRef = dottedToAccess(`f.${agg.field}`)
329 return `MIN(${fieldRef}) AS ${key}`
330 }
331 case "agg-max": {
332 const fieldRef = dottedToAccess(`f.${agg.field}`)
333 return `MAX(${fieldRef}) AS ${key}`
334 }
335 default:
336 return assertUnreachable(agg)
337 }
338 }
339
340 const computedSelectExpr = (key: string, computed: ComputedProjectionIrExpression) => {
341 const relationPath = computed.path

Callers 1

buildSelectListFunction · 0.70

Calls 3

assertUnreachableFunction · 0.90
dottedToAccessFunction · 0.85
printFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…