Metakit / @doeixd/metakit/aggregates

sum

function · packages/metakit/src/aggregates.ts:303

function sum<S extends Schema.Top, A extends number>(
  rowSchema: S,
  build: (
    $: PathAccessor<S['Type'], S['Type']>,
  ) => ExprInput<S['Type'], A | null>,
): Sum<S['Type'], A>

The sum of an integer-valued contribution over the rows (0 when empty; a null contribution adds nothing). The contribution must read only integer-valued fields (Schema.Int, Money, Decimal) and integer literals through +, -, *, negation, if and match; anything else is refused, because its deltas would drift.