on master help sign in
Add Monoid instance for Query (#207)
commitd2f05bdcfd450bba7bbb2a4fd7172a9214b23f65 authorShane <shane.obrien@circuithub.com> dateMon 17 Oct 2022, 12:00 (4 years ago) parent5eb5689
1 file changed+14−1
src/Rel8/Query.hs+14−1
src/Rel8/Query.hs+14−1
@@ -1,4 +1,6 @@
1+{-# language FlexibleContexts #-}
12{-# language StandaloneKindSignatures #-}
3+{-# language UndecidableInstances #-}
24
35module Rel8.Query
46 ( Query( Query )
@@ -20,10 +22,11 @@ import qualified Opaleye.Internal.QueryArr as Opaleye
2022import qualified Opaleye.Internal.Tag as Opaleye
2123
2224-- rel8
25+import Rel8.Expr ( Expr )
2326import Rel8.Query.Set ( unionAll )
2427import Rel8.Query.Opaleye ( fromOpaleye )
2528import Rel8.Query.Values ( values )
26−import Rel8.Table ( fromColumns, toColumns )
29+import Rel8.Table ( Table, fromColumns, toColumns )
2730import Rel8.Table.Alternative
2831 ( AltTable, (<|>:)
2932 , AlternativeTable, emptyTable
@@ -208,3 +211,13 @@ instance AltTable Query where
208211-- | 'emptyTable' = 'values' @[]@.
209212instance AlternativeTable Query where
210213 emptyTable = values []
214+
215+
216+-- | '<>' = 'unionAll'.
217+instance Table Expr a => Semigroup (Query a) where
218+ (<>) = (<|>:)
219+
220+
221+-- | 'mempty' = @'values' []@.
222+instance Table Expr a => Monoid (Query a) where
223+ mempty = emptyTable