@@ -104,25 +104,31 @@ coalesce nulls isn'tNull = UnsafeExpression $
104 "COALESCE" <> parenthesized (commaSeparated
104 "COALESCE" <> parenthesized (commaSeparated
105 ((renderExpression <$> nulls) <> [renderExpression isn'tNull]))
105 ((renderExpression <$> nulls) <> [renderExpression isn'tNull]))
108+ :: Expression params tables grouping ('Required ('NotNull x))
109+ -> Expression params tables grouping ('Required ('Null x))
110+ -> Expression params tables grouping ('Required ('NotNull x))
111+fromNull isn'tNull isNull = coalesce [isNull] isn'tNull
107unsafeBinaryOp
113unsafeBinaryOp
108 :: ByteString
114 :: ByteString
109− -> Expression params tables grouping ty0
115+ -> Expression params tables grouping ('Required ty0)
110− -> Expression params tables grouping ty1
116+ -> Expression params tables grouping ('Required ty1)
111− -> Expression params tables grouping ty2
117+ -> Expression params tables grouping ('Required ty2)
112unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
118unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
113 renderExpression x <+> op <+> renderExpression y
119 renderExpression x <+> op <+> renderExpression y
115unsafeUnaryOp
121unsafeUnaryOp
116 :: ByteString
122 :: ByteString
117− -> Expression params tables grouping ty0
123+ -> Expression params tables grouping ('Required ty0)
118− -> Expression params tables grouping ty1
124+ -> Expression params tables grouping ('Required ty1)
119unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
125unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
120 op <+> renderExpression x
126 op <+> renderExpression x
122unsafeFunction
128unsafeFunction
123 :: ByteString
129 :: ByteString
124− -> Expression params tables grouping xty
130+ -> Expression params tables grouping ('Required xty)
125− -> Expression params tables grouping yty
131+ -> Expression params tables grouping ('Required yty)
126unsafeFunction fun x = UnsafeExpression $
132unsafeFunction fun x = UnsafeExpression $
127 fun <> parenthesized (renderExpression x)
133 fun <> parenthesized (renderExpression x)
@@ -283,9 +289,11 @@ not_ = unsafeUnaryOp "NOT"
283(||*) = unsafeBinaryOp "OR"
289(||*) = unsafeBinaryOp "OR"
285caseWhenThenElse
291caseWhenThenElse
286− :: [(Condition params tables grouping, Expression params tables grouping ty)]
292+ :: [ ( Condition params tables grouping
293+ , Expression params tables grouping ('Required ty)
287− -> Expression params tables grouping ty
295+ -> Expression params tables grouping ('Required ty)
288− -> Expression params tables grouping ty
296+ -> Expression params tables grouping ('Required ty)
289caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
297caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
291 , mconcat
299 , mconcat
@@ -301,9 +309,9 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
302ifThenElse
310ifThenElse
303 :: Condition params tables grouping
311 :: Condition params tables grouping
304− -> Expression params tables grouping ty
312+ -> Expression params tables grouping ('Required ty)
305− -> Expression params tables grouping ty
313+ -> Expression params tables grouping ('Required ty)
306− -> Expression params tables grouping ty
314+ -> Expression params tables grouping ('Required ty)
307ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
315ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
@@ -440,8 +448,8 @@ instance
441unsafeAggregate
449unsafeAggregate
442 :: ByteString
450 :: ByteString
443− -> Expression params tables 'Ungrouped xty
451+ -> Expression params tables 'Ungrouped ('Required xty)
444− -> Expression params tables ('Grouped bys) yty
452+ -> Expression params tables ('Grouped bys) ('Required yty)
445unsafeAggregate fun x = UnsafeExpression $ mconcat
453unsafeAggregate fun x = UnsafeExpression $ mconcat
446 [fun, "(", renderExpression x, ")"]
454 [fun, "(", renderExpression x, ")"]
@@ -451,6 +459,90 @@ sum_
451 -> Expression params tables ('Grouped bys) ('Required (nullity ty))
459 -> Expression params tables ('Grouped bys) ('Required (nullity ty))
452sum_ = unsafeAggregate "sum"
460sum_ = unsafeAggregate "sum"
464+ => Expression params tables 'Ungrouped ('Required (nullity int))
465+ -> Expression params tables ('Grouped bys) ('Required (nullity 'PGnumeric))
466+avgInt = unsafeAggregate "avg"
470+ => Expression params tables 'Ungrouped ('Required (nullity float))
471+ -> Expression params tables ('Grouped bys) ('Required (nullity 'PGfloat8))
472+avgFloat = unsafeAggregate "avg"
476+ => Expression params tables 'Ungrouped ('Required (nullity int))
477+ -> Expression params tables ('Grouped bys) ('Required (nullity int))
478+bitAnd = unsafeAggregate "bit_and"
482+ => Expression params tables 'Ungrouped ('Required (nullity int))
483+ -> Expression params tables ('Grouped bys) ('Required (nullity int))
484+bitOr = unsafeAggregate "bit_or"
487+ :: Expression params tables 'Ungrouped ('Required (nullity 'PGbool))
488+ -> Expression params tables ('Grouped bys) ('Required (nullity 'PGbool))
489+boolAnd = unsafeAggregate "bool_and"
492+ :: Expression params tables 'Ungrouped ('Required (nullity 'PGbool))
493+ -> Expression params tables ('Grouped bys) ('Required (nullity 'PGbool))
494+boolOr = unsafeAggregate "bool_or"
497+ :: Expression params table ('Grouped bys) ('Required ('NotNull 'PGint8))
498+countStar = UnsafeExpression "count(*)"
501+ :: Expression params tables 'Ungrouped ('Required ty)
502+ -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGint8))
503+count = unsafeAggregate "count"
506+ :: Expression params tables 'Ungrouped ('Required (nullity 'PGbool))
507+ -> Expression params tables ('Grouped bys) ('Required (nullity 'PGbool))
508+every = unsafeAggregate "every"
511+ :: Expression params tables 'Ungrouped ('Required ty)
512+ -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGjson))
513+jsonAgg = unsafeAggregate "json_agg"
516+ :: Expression params tables 'Ungrouped ('Required ty)
517+ -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGjsonb))
518+jsonbAgg = unsafeAggregate "jsonb_agg"
521+ :: Expression params tables 'Ungrouped ('Required ('NotNull keyty))
522+ -> Expression params tables 'Ungrouped ('Required valty)
523+ -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGjson))
524+jsonObjectAgg k v = UnsafeExpression $
525+ "json_object_agg(" <> renderExpression k
526+ <> ", " <> renderExpression v <> ")"
529+ :: Expression params tables 'Ungrouped ('Required ('NotNull keyty))
530+ -> Expression params tables 'Ungrouped ('Required valty)
531+ -> Expression params tables ('Grouped bys) ('Required ('NotNull 'PGjsonb))
532+jsonbObjectAgg k v = UnsafeExpression $
533+ "jsonb_object_agg(" <> renderExpression k
534+ <> ", " <> renderExpression v <> ")"
537+ :: Expression params tables 'Ungrouped ('Required (nullity ty))
538+ -> Expression params tables ('Grouped bys) ('Required (nullity ty))
539+max_ = unsafeAggregate "max"
542+ :: Expression params tables 'Ungrouped ('Required (nullity ty))
543+ -> Expression params tables ('Grouped bys) ('Required (nullity ty))
544+min_ = unsafeAggregate "min"
454{-----------------------------------------
546{-----------------------------------------
456-----------------------------------------}
548-----------------------------------------}