on 03b366b help sign in
rel8/src/Rel8/Expr/Array.hs
53 lines 1.5 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language ScopedTypeVariables #-}
4{-# language TypeApplications #-}
5{-# language TypeFamilies #-}
7{-# options_ghc -fno-warn-redundant-constraints #-}
9module Rel8.Expr.Array
10 ( listOf, nonEmptyOf
11 , sappend, sappend1, sempty
12 )
13where
15-- base
16import Data.List.NonEmpty ( NonEmpty )
17import Prelude
19-- opaleye
20import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
22-- rel8
23import {-# SOURCE #-} Rel8.Expr ( Expr )
24import Rel8.Expr.Opaleye
25 ( fromPrimExpr, toPrimExpr
26 , zipPrimExprsWith
27 )
28import Rel8.Type ( DBType, typeInformation )
29import Rel8.Type.Array ( array, zipPrimArraysWith )
30import Rel8.Type.Information ( TypeInformation(..) )
31import Rel8.Schema.Nullability ( Nullability, Nullabilizes )
34sappend :: Expr [a] -> Expr [a] -> Expr [a]
35sappend = zipPrimExprsWith (zipPrimArraysWith (Opaleye.BinExpr (Opaleye.:||)))
38sappend1 :: Expr (NonEmpty a) -> Expr (NonEmpty a) -> Expr (NonEmpty a)
39sappend1 = zipPrimExprsWith (zipPrimArraysWith (Opaleye.BinExpr (Opaleye.:||)))
42sempty :: Nullability t a -> TypeInformation t -> Expr [a]
43sempty _ info = fromPrimExpr $ array info []
46listOf :: forall a t. (Nullabilizes t a, DBType t)
47 => [Expr a] -> Expr [a]
48listOf = fromPrimExpr . array (typeInformation @t) . fmap toPrimExpr
51nonEmptyOf :: forall a t. (Nullabilizes t a, DBType t)
52 => NonEmpty (Expr a) -> Expr (NonEmpty a)
53nonEmptyOf = fromPrimExpr . array (typeInformation @t) . fmap toPrimExpr