Metakit / API
@doeixd/metakit/aggregates
Cross-record Aggregates (@doeixd/metakit/aggregates). This module evaluates in
memory and imports no SQL, so a page can use it; @doeixd/metakit/aggregates/sql
compiles the same aggregates to SQL. What each keeps is not declared here:
it is read off the fold's row of foldProperties.
- Totals (
Rows.sum,Rows.count): the foldssumandcountare commutative, associative and invertible over the integers, so an insert, update or delete moves the value by an O(1) delta (new - old), starting from the fold's identity. The delta is exact only over that domain, so the contribution must be integer-valued (aSchema.Int,MoneyorDecimalfield, or integer arithmetic over them): floating-point addition is not invertible (0.1 + 0.2 + 0.3 - 0.2is0.4000000000000001). A difference of two safe totals may leave the safe range itself, soupdateDeltarefuses it andreplaceTotalcomputes the exact next total instead. The symbolic deltas letProve.transitionprove a rule over any number of rows. - Extremes and tests (
Rows.min,Rows.max,Rows.every,Rows.any): their folds are not invertible, so an insert is O(1) while deleting or updating the extremum rescans the rows.
Missing values follow SQL: sum, min and max skip a null
contribution, count with a predicate and any count an unknown predicate
as false, and every counts it as failing (coalesce(p, false)).
evaluate is the kernel's fold of the same body over the rows (Arr.sum,
Arr.any and the rest), so an aggregate and that fold in an expression
give one answer: any and every settle past a row whose predicate
refuses, sum, min and max refuse non-finite where a value is NaN or
an infinity, and a value its Schema rejects gets the fold's answer.
Functions
any | Semilattice aggregate: true when some row's predicate is true (false when empty). A row whose predicate refuses refuses the whole only where no row holds. |
count | The number of rows, or of rows whose predicate is true. |
every | Semilattice aggregate: true when every row's predicate is true (true when empty). A row whose predicate is unknown counts as failing. A row whose predicate… |
max | Semilattice aggregate: the largest non-null value (Option.none() when there is none), refused non-finite where a value is NaN or an infinity. |
min | Semilattice aggregate: the smallest non-null value (Option.none() when there is none), refused non-finite where a value is NaN or an infinity. |
sum | 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… |
Interfaces
Any | Rows.any: true when some row's predicate is true (false when empty). |
Count | Rows.count: the number of rows, or of rows whose predicate is true. |
Every | Rows.every: true when no row's predicate is false or unknown (true when empty). |
Max | Rows.max: the largest non-null value (Option.none() when there is none). |
Min | Rows.min: the smallest non-null value (Option.none() when there is none). |
Sum | Rows.sum: the sum of an integer-valued contribution (0 when empty). |