on 0f76861 help sign in
rel8/src/Rel8/Query/Set.hs
58 lines 2.0 kB history raw
1{-# language FlexibleContexts #-}
3module Rel8.Query.Set
4 ( union, unionAll
5 , intersect, intersectAll
6 , except, exceptAll
7 )
8where
10-- base
11import Prelude ()
13-- opaleye
14import qualified Opaleye.Binary as Opaleye
16-- rel8
17import Rel8.Expr ( Expr )
18import {-# SOURCE #-} Rel8.Query ( Query )
19import Rel8.Query.Opaleye ( zipOpaleyeWith )
20import Rel8.Table ( Table )
21import Rel8.Table.Eq ( EqTable )
22import Rel8.Table.Opaleye ( binaryspec )
25-- | Combine the results of two queries of the same type, collapsing
26-- duplicates. @union a b@ is the same as the SQL statement @x UNION b@.
27union :: EqTable a => Query a -> Query a -> Query a
28union = zipOpaleyeWith (Opaleye.unionExplicit binaryspec)
31-- | Combine the results of two queries of the same type, retaining duplicates.
32-- @unionAll a b@ is the same as the SQL statement @x UNION ALL b@.
33unionAll :: Table Expr a => Query a -> Query a -> Query a
34unionAll = zipOpaleyeWith (Opaleye.unionAllExplicit binaryspec)
37-- | Find the intersection of two queries, collapsing duplicates. @intersect a
38-- b@ is the same as the SQL statement @x INTERSECT b@.
39intersect :: EqTable a => Query a -> Query a -> Query a
40intersect = zipOpaleyeWith (Opaleye.intersectExplicit binaryspec)
43-- | Find the intersection of two queries, retaining duplicates. @intersectAll
44-- a b@ is the same as the SQL statement @x INTERSECT ALL b@.
45intersectAll :: EqTable a => Query a -> Query a -> Query a
46intersectAll = zipOpaleyeWith (Opaleye.intersectAllExplicit binaryspec)
49-- | Find the difference of two queries, collapsing duplicates @except a b@ is
50-- the same as the SQL statement @x INTERSECT b@.
51except :: EqTable a => Query a -> Query a -> Query a
52except = zipOpaleyeWith (Opaleye.exceptExplicit binaryspec)
55-- | Find the difference of two queries, retaining duplicates. @exceptAll a b@
56-- is the same as the SQL statement @x EXCEPT ALL b@.
57exceptAll :: EqTable a => Query a -> Query a -> Query a
58exceptAll = zipOpaleyeWith (Opaleye.exceptAllExplicit binaryspec)