on master help sign in
Document more aggregation operators
b5fc074Ollie Charles
src/Rel8/Expr/Aggregate.hs+6
@@ -46,6 +46,7 @@ import Rel8.Type.String ( DBString )
46import Rel8.Type.Sum ( DBSum )
46import Rel8.Type.Sum ( DBSum )
47
47
48
48
49+-- | Count the occurances of a single column. Corresponds to @COUNT(a)@
49count :: Expr a -> Aggregate (Expr Int64)
50count :: Expr a -> Aggregate (Expr Int64)
50count = unsafeMakeAggregate toPrimExpr fromPrimExpr $
51count = unsafeMakeAggregate toPrimExpr fromPrimExpr $
51 Just Aggregator
52 Just Aggregator
@@ -55,6 +56,8 @@ count = unsafeMakeAggregate toPrimExpr fromPrimExpr $
55 }
56 }
56
57
57
58
59+-- | Count the number of distinct occurances of a single column. Corresponds to
60+-- @COUNT(DISTINCT a)@
58countDistinct :: DBEq a => Expr a -> Aggregate (Expr Int64)
61countDistinct :: DBEq a => Expr a -> Aggregate (Expr Int64)
59countDistinct = unsafeMakeAggregate toPrimExpr fromPrimExpr $
62countDistinct = unsafeMakeAggregate toPrimExpr fromPrimExpr $
60 Just Aggregator
63 Just Aggregator
@@ -64,6 +67,7 @@ countDistinct = unsafeMakeAggregate toPrimExpr fromPrimExpr $
64 }
67 }
65
68
66
69
70+-- | Corresponds to @COUNT(*)@.
67countStar :: Aggregate (Expr Int64)
71countStar :: Aggregate (Expr Int64)
68countStar = count (litExpr True)
72countStar = count (litExpr True)
69
73
@@ -72,6 +76,7 @@ countWhere :: Expr Bool -> Aggregate (Expr Int64)
72countWhere condition = count (caseExpr [(condition, litExpr (Just True))] null)
76countWhere condition = count (caseExpr [(condition, litExpr (Just True))] null)
73
77
74
78
79+-- | Corresponds to @bool_and@.
75and :: Expr Bool -> Aggregate (Expr Bool)
80and :: Expr Bool -> Aggregate (Expr Bool)
76and = unsafeMakeAggregate toPrimExpr fromPrimExpr $
81and = unsafeMakeAggregate toPrimExpr fromPrimExpr $
77 Just Aggregator
82 Just Aggregator
@@ -81,6 +86,7 @@ and = unsafeMakeAggregate toPrimExpr fromPrimExpr $
81 }
86 }
82
87
83
88
89+-- | Corresponds to @bool_or@.
84or :: Expr Bool -> Aggregate (Expr Bool)
90or :: Expr Bool -> Aggregate (Expr Bool)
85or = unsafeMakeAggregate toPrimExpr fromPrimExpr $
91or = unsafeMakeAggregate toPrimExpr fromPrimExpr $
86 Just Aggregator
92 Just Aggregator