import {EnforceNonEmptyRecord, ValueRecord} from '../../record' import {AggregatableTable} from '../aggregatable_table' import {aggregateGroups, SelectRows} from '../selection/select_rows' import {SortGrouping} from './sort_grouping' import { addAscendingGroupOrder, addDescendingGroupOrder, GroupSelectStatement } from '../../statements/group_select_statement' import {Value} from '../../value' export class GroupTable { constructor(private readonly statement: GroupSelectStatement) {} sortBy(sortBy: (key: K, table: AggregatableTable, count: () => number) => Value): SortGrouping { return new SortGrouping(addAscendingGroupOrder(this.statement, sortBy)) } sortDescendinglyBy(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) } }