rel8-internal
Safe HaskellNone
LanguageHaskell2010

Rel8.Internal.Table.Aggregate

Synopsis

Documentation

groupBy :: EqTable a => Aggregator1 a a Source #

Group equal tables together. This works by aggregating each column in the given table with groupByExpr.

For example, if we have a table of items, we could group the items by the order they belong to:

itemsByOrder :: Query (OrderId Expr, ListTable Expr (Item Expr))
itemsByOrder =
  aggregate
    do
      orderId <- groupByOn (.orderId)
      items <- listAgg
      pure (orderId, items)
    do
      each itemSchema

groupByOn :: EqTable a => (i -> a) -> Aggregator1 i a Source #

Applies groupBy to the columns selected by the given function.

listAgg :: forall a (fold :: Fold). Table Expr a => Aggregator' fold a (ListTable Expr a) Source #

Aggregate rows into a single row containing an array of all aggregated rows. This can be used to associate multiple rows with a single row, without changing the over cardinality of the query. This allows you to essentially return a tree-like structure from queries.

For example, if we have a table of orders and each orders contains multiple items, we could aggregate the table of orders, pairing each order with its items:

ordersWithItems :: Query (Order Expr, ListTable Expr (Item Expr))
ordersWithItems = do
  order <- each orderSchema
  items <- aggregate listAgg (itemsFromOrder order)
  return (order, items)

listAggOn :: forall a i (fold :: Fold). Table Expr a => (i -> a) -> Aggregator' fold i (ListTable Expr a) Source #

Applies listAgg to the columns selected by the given function.

nonEmptyAgg :: Table Expr a => Aggregator1 a (NonEmptyTable Expr a) Source #

Like listAgg, but the result is guaranteed to be a non-empty list.

nonEmptyAggOn :: Table Expr a => (i -> a) -> Aggregator1 i (NonEmptyTable Expr a) Source #

Applies nonEmptyAgg to the columns selected by the given function.

listCat :: forall a (fold :: Fold). Table Expr a => Aggregator' fold (ListTable Expr a) (ListTable Expr a) Source #

Concatenate lists into a single list.

listCatOn :: forall a i (fold :: Fold). Table Expr a => (i -> ListTable Expr a) -> Aggregator' fold i (ListTable Expr a) Source #

Applies listCat to the list selected by the given function.

nonEmptyCat :: Table Expr a => Aggregator1 (NonEmptyTable Expr a) (NonEmptyTable Expr a) Source #

Concatenate non-empty lists into a single non-empty list.

nonEmptyCatOn :: Table Expr a => (i -> NonEmptyTable Expr a) -> Aggregator1 i (NonEmptyTable Expr a) Source #

Applies nonEmptyCat to the non-empty list selected by the given function.

filterWhere :: forall a i (fold :: Fold). Table Expr a => (i -> Expr Bool) -> Aggregator i a -> Aggregator' fold i a Source #

filterWhere allows an Aggregator to filter out rows from the input query before considering them for aggregation. Note that because the predicate supplied to filterWhere could return false for every row, filterWhere needs an Aggregator as opposed to an Aggregator1, so that it can return a default value in such a case. For a variant of filterWhere that can work with Aggregator1s, see filterWhereOptional.

orderAggregateBy :: forall i (fold :: Fold) a. Order i -> Aggregator' fold i a -> Aggregator' fold i a Source #

Order the values within each aggregation in an Aggregator using the given ordering. This is only relevant for aggregations that depend on the order they get their elements, like listAgg and stringAgg.