1{-# language FlexibleContexts #-}
2{-# language MonoLocalBinds #-}
4module Rel8.Query.Aggregate
11import Data.Int ( Int64 )
15import qualified Opaleye.Aggregate as Opaleye
18import Rel8.Aggregate ( Aggregates )
19import Rel8.Expr ( Expr )
20import Rel8.Expr.Aggregate ( countStar )
21import Rel8.Query ( Query )
22import Rel8.Query.Maybe ( optional )
23import Rel8.Query.Opaleye ( mapOpaleye )
24import Rel8.Table.Opaleye ( aggregator )
25import Rel8.Table.Maybe ( maybeTable )
28-- | Apply an aggregation to all rows returned by a 'Query'.
29aggregate :: Aggregates aggregates exprs => Query aggregates -> Query exprs
30aggregate = mapOpaleye (Opaleye.aggregate aggregator)
33-- | Count the number of rows returned by a query. Note that this is different
34-- from @countStar@, as even if the given query yields no rows, @countRows@
36countRows :: Query a -> Query (Expr Int64)
37countRows = fmap (maybeTable 0 id) . optional . aggregate . fmap (const countStar)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list