import {EnforceNonEmptyRecord, ValueRecord} from '../../record' import {AggregatableTable} from '../aggregatable_table' import {aggregateGroups, SelectRows} from '../selection/select_rows' import { addAscendingGroupOrder, addDescendingGroupOrder, GroupSelectStatement } from '../../statements/group_select_statement' import {Value} from '../../value' export class SortGrouping { constructor(private readonly statement: GroupSelectStatement) {} thenBy(sortBy: (key: K, table: AggregatableTable, count: () => number) => Value): SortGrouping { return new SortGrouping(addAscendingGroupOrder(this.statement, sortBy)) } thenDescendinglyBy(sortBy: (key: K, table: AggregatableTable, count: () => number) => Value): SortGrouping { return new SortGrouping(addDescendingGroupOrder(this.statement, sortBy)) } aggregate( aggregation: (key: K, table: AggregatableTable, count: () => number) => EnforceNonEmptyRecord & A): SelectRows { return aggregateGroups(this.statement, aggregation) } }