English | 简体中文

api-docs / org.ktorm.entity / aggregateColumnsTo

aggregateColumnsTo

inline fun <E : Any, T : BaseTable<E>, K : Any, C : Any, M : MutableMap<in K?, in C?>> EntityGrouping<E, T, K>.aggregateColumnsTo(
    destination: M,
    aggregationSelector: (T) -> ColumnDeclaring<C>
): M
(source code)

Group elements from the source sequence by key and perform the given aggregation for elements in each group,
then store the results in the destination map.

The key for each group is provided by the EntityGrouping.keySelector function, and the generated SQL is like:
select key, aggregation from source group by key.

Ktorm also supports aggregating two or more columns, we just need to wrap our aggregate expressions by tupleOf
in the closure, then the function’s return type becomes Map<K?, TupleN<C1?, C2?, .. Cn?>>.

Parameters

destination - a MutableMap used to store the results.

aggregationSelector - a function that accepts the source table and returns the aggregate expression.

Return
the destination map associating the key of each group with the result of aggregation of the group elements.