on 28aaa76 help sign in
rel8/src/Rel8/Query.hs
50 lines 1.1 kB history raw
1{-# language DerivingStrategies #-}
2{-# language DerivingVia #-}
3{-# language GeneralizedNewtypeDeriving #-}
4{-# language StandaloneKindSignatures #-}
6module Rel8.Query
7 ( Query( Query )
8 )
9where
11-- base
12import Data.Kind ( Type )
13import Prelude
15-- opaleye
16import qualified Opaleye.Select as Opaleye
18-- rel8
19import Rel8.Query.Set ( unionAll )
20import Rel8.Query.Values ( values )
21import Rel8.Table.Alternative
22 ( AltTable, (<|>:)
23 , AlternativeTable, emptyTable
24 )
26-- semigroupoids
27import Data.Functor.Apply ( Apply, WrappedApplicative(..) )
28import Data.Functor.Bind ( Bind, (>>-) )
31-- | The @Query@ monad allows you to compose a @SELECT@ query. This monad has
32-- semantics similar to the list (@[]@) monad.
33type Query :: Type -> Type
34newtype Query a = Query (Opaleye.Select a)
35 deriving newtype (Functor, Applicative, Monad)
36 deriving Apply via (WrappedApplicative Opaleye.Select)
39instance Bind Query where
40 (>>-) = (>>=)
43-- | '<|>:' = 'unionAll'.
44instance AltTable Query where
45 (<|>:) = unionAll
48-- | 'emptyTable' = 'values' @[]@.
49instance AlternativeTable Query where
50 emptyTable = values []