on master help sign in
Document more aggregation operators
commitb5fc074f67310d833dc37c3668cf00674cd395b8 authorOllie Charles <ollie@ocharles.org.uk> dateTue 23 Mar 2021, 16:31 (6 years ago) parent0787c47
1 file changed+6
src/Rel8/Expr/Aggregate.hs+6
src/Rel8/Expr/Aggregate.hs+6
@@ -46,6 +46,7 @@ import Rel8.Type.String ( DBString )
4646import Rel8.Type.Sum ( DBSum )
4747
4848
49+-- | Count the occurances of a single column. Corresponds to @COUNT(a)@
4950count :: Expr a -> Aggregate (Expr Int64)
5051count = unsafeMakeAggregate toPrimExpr fromPrimExpr $
5152 Just Aggregator
@@ -55,6 +56,8 @@ count = unsafeMakeAggregate toPrimExpr fromPrimExpr $
5556 }
5657
5758
59+-- | Count the number of distinct occurances of a single column. Corresponds to
60+-- @COUNT(DISTINCT a)@
5861countDistinct :: DBEq a => Expr a -> Aggregate (Expr Int64)
5962countDistinct = unsafeMakeAggregate toPrimExpr fromPrimExpr $
6063 Just Aggregator
@@ -64,6 +67,7 @@ countDistinct = unsafeMakeAggregate toPrimExpr fromPrimExpr $
6467 }
6568
6669
70+-- | Corresponds to @COUNT(*)@.
6771countStar :: Aggregate (Expr Int64)
6872countStar = count (litExpr True)
6973
@@ -72,6 +76,7 @@ countWhere :: Expr Bool -> Aggregate (Expr Int64)
7276countWhere condition = count (caseExpr [(condition, litExpr (Just True))] null)
7377
7478
79+-- | Corresponds to @bool_and@.
7580and :: Expr Bool -> Aggregate (Expr Bool)
7681and = unsafeMakeAggregate toPrimExpr fromPrimExpr $
7782 Just Aggregator
@@ -81,6 +86,7 @@ and = unsafeMakeAggregate toPrimExpr fromPrimExpr $
8186 }
8287
8388
89+-- | Corresponds to @bool_or@.
8490or :: Expr Bool -> Aggregate (Expr Bool)
8591or = unsafeMakeAggregate toPrimExpr fromPrimExpr $
8692 Just Aggregator