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

Function compileExpr

packages/infra/src/Store/SQL/query.ts:406–415  ·  view source on GitHub ↗
(expression: ComputedProjectionMathIrExpression)

Source from the content-addressed store, hash-verified

404 const toNumber = (expr: string) =>
405 dialect.jsonColumnType === "JSON" ? `CAST(${expr} AS REAL)` : `(${expr})::numeric`
406 const compileExpr = (expression: ComputedProjectionMathIrExpression): string => {
407 switch (expression._tag) {
408 case "field":
409 return toNumber(dialect.jsonExtractElement(relationAlias, expression.field))
410 case "mul":
411 return `(${compileExpr(expression.left)} * ${compileExpr(expression.right)})`
412 default:
413 return assertUnreachable(expression)
414 }
415 }
416 const factorCaseExpr = (unitExpr: string, toBase: string, factors: Readonly<Record<string, number>>) => {
417 const entries = Object.entries(factors).filter(([, factor]) => Number.isFinite(factor))
418 const cases = entries.map(([unit, factor]) => ` WHEN ${sqlStringLiteral(unit)} THEN ${factor}`).join("")

Callers 1

computedSelectExprFunction · 0.70

Calls 2

assertUnreachableFunction · 0.90
toNumberFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…