over method
Turns an aggregate into a window expression.
Partition and ordering expressions cannot contain nested windows. The selected database must support window functions.
Implementation
Expr<T> over({
List<Expr<Object?>> partitionBy = const [],
List<OrderTerm> orderBy = const [],
WindowFrame? frame,
}) {
final function = unwrapStorage(expressionNode);
if ((function is! FunctionNode && function is! DecimalAverage) ||
!aggregate(function)) {
throw const OrmException(
'QUERY.WINDOW',
'over() applies to an aggregate expression.',
);
}
if ([
...partitionBy.map((e) => e.expressionNode),
...orderBy.map((o) => o.expression.expressionNode),
].any(window)) {
throw const OrmException(
'QUERY.WINDOW',
'Window partition/order expressions cannot contain another window.',
);
}
return Expr.internal(
WindowNode(
function,
List.unmodifiable(partitionBy),
List.unmodifiable(orderBy),
frame,
),
codec,
);
}