withSum<TChild, V> method
MssqlProjectedQuery<(TRow, V?)>
withSum<TChild, V>(
- MssqlRelation<
TRow, TChild> relation(- TFields fields
- MssqlExpression operand
Parent rows plus SUM of operand on matching children.
V is the Dart type the operand's SQL type decodes to, and it is
unbounded: a V extends num bound would exclude MssqlDecimal and so
force the sum of a decimal or money column through double, which
is the rounding exact decimal exists to prevent. So write
withSum<OrderLine, MssqlDecimal>(…) for an exact column and
withSum<OrderLine, int>(…) for an integer one. A V the value cannot
become is a located error naming the aggregate, not a silent cast.
An empty match is SQL NULL, not zero — "the sum of no rows" has no
value — so the result is V?.
Implementation
MssqlProjectedQuery<(TRow, V?)> withSum<TChild, V>(
MssqlRelation<TRow, TChild> Function(TFields fields) relation,
MssqlExpression operand,
) {
return _withAggregate(
relation,
MssqlAggregate.sum(operand),
(v) => _decodeAggregate<V>('withSum', v),
);
}