{-# language DataKinds #-}
{-# language FlexibleContexts #-}
{-# language TypeFamilies #-}

{-# options_ghc -fno-warn-redundant-constraints #-}

module Rel8.Expr.Array
  ( listOf, nonEmptyOf
  , slistOf, snonEmptyOf
  , sappend, sappend1, sempty
  )
where

-- base
import Data.List.NonEmpty ( NonEmpty )
import Prelude

-- opaleye
import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye

-- rel8
import {-# SOURCE #-} Rel8.Expr ( Expr )
import Rel8.Expr.Opaleye
  ( fromPrimExpr, toPrimExpr
  , zipPrimExprsWith
  )
import Rel8.Type ( DBType, typeInformation )
import Rel8.Type.Array ( array )
import Rel8.Type.Information ( TypeInformation(..) )
import Rel8.Schema.Null ( Unnullify, Sql )


sappend :: Expr [a] -> Expr [a] -> Expr [a]
sappend :: Expr [a] -> Expr [a] -> Expr [a]
sappend = (PrimExpr -> PrimExpr -> PrimExpr)
-> Expr [a] -> Expr [a] -> Expr [a]
forall a b c.
(PrimExpr -> PrimExpr -> PrimExpr) -> Expr a -> Expr b -> Expr c
zipPrimExprsWith (BinOp -> PrimExpr -> PrimExpr -> PrimExpr
Opaleye.BinExpr BinOp
(Opaleye.:||))


sappend1 :: Expr (NonEmpty a) -> Expr (NonEmpty a) -> Expr (NonEmpty a)
sappend1 :: Expr (NonEmpty a) -> Expr (NonEmpty a) -> Expr (NonEmpty a)
sappend1 = (PrimExpr -> PrimExpr -> PrimExpr)
-> Expr (NonEmpty a) -> Expr (NonEmpty a) -> Expr (NonEmpty a)
forall a b c.
(PrimExpr -> PrimExpr -> PrimExpr) -> Expr a -> Expr b -> Expr c
zipPrimExprsWith (BinOp -> PrimExpr -> PrimExpr -> PrimExpr
Opaleye.BinExpr BinOp
(Opaleye.:||))


sempty :: TypeInformation (Unnullify a) -> Expr [a]
sempty :: TypeInformation (Unnullify a) -> Expr [a]
sempty TypeInformation (Unnullify a)
info = PrimExpr -> Expr [a]
forall a. PrimExpr -> Expr a
fromPrimExpr (PrimExpr -> Expr [a]) -> PrimExpr -> Expr [a]
forall a b. (a -> b) -> a -> b
$ TypeInformation (Unnullify a) -> [PrimExpr] -> PrimExpr
forall (f :: * -> *) a.
Foldable f =>
TypeInformation a -> f PrimExpr -> PrimExpr
array TypeInformation (Unnullify a)
info []


slistOf :: TypeInformation (Unnullify a) -> [Expr a] -> Expr [a]
slistOf :: TypeInformation (Unnullify a) -> [Expr a] -> Expr [a]
slistOf TypeInformation (Unnullify a)
info = PrimExpr -> Expr [a]
forall a. PrimExpr -> Expr a
fromPrimExpr (PrimExpr -> Expr [a])
-> ([Expr a] -> PrimExpr) -> [Expr a] -> Expr [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeInformation (Unnullify a) -> [PrimExpr] -> PrimExpr
forall (f :: * -> *) a.
Foldable f =>
TypeInformation a -> f PrimExpr -> PrimExpr
array TypeInformation (Unnullify a)
info ([PrimExpr] -> PrimExpr)
-> ([Expr a] -> [PrimExpr]) -> [Expr a] -> PrimExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Expr a -> PrimExpr) -> [Expr a] -> [PrimExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr a -> PrimExpr
forall a. Expr a -> PrimExpr
toPrimExpr


snonEmptyOf :: TypeInformation (Unnullify a) -> NonEmpty (Expr a) -> Expr (NonEmpty a)
snonEmptyOf :: TypeInformation (Unnullify a)
-> NonEmpty (Expr a) -> Expr (NonEmpty a)
snonEmptyOf TypeInformation (Unnullify a)
info = PrimExpr -> Expr (NonEmpty a)
forall a. PrimExpr -> Expr a
fromPrimExpr (PrimExpr -> Expr (NonEmpty a))
-> (NonEmpty (Expr a) -> PrimExpr)
-> NonEmpty (Expr a)
-> Expr (NonEmpty a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeInformation (Unnullify a) -> NonEmpty PrimExpr -> PrimExpr
forall (f :: * -> *) a.
Foldable f =>
TypeInformation a -> f PrimExpr -> PrimExpr
array TypeInformation (Unnullify a)
info (NonEmpty PrimExpr -> PrimExpr)
-> (NonEmpty (Expr a) -> NonEmpty PrimExpr)
-> NonEmpty (Expr a)
-> PrimExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Expr a -> PrimExpr) -> NonEmpty (Expr a) -> NonEmpty PrimExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr a -> PrimExpr
forall a. Expr a -> PrimExpr
toPrimExpr


listOf :: Sql DBType a => [Expr a] -> Expr [a]
listOf :: [Expr a] -> Expr [a]
listOf = TypeInformation (Unnullify a) -> [Expr a] -> Expr [a]
forall a. TypeInformation (Unnullify a) -> [Expr a] -> Expr [a]
slistOf TypeInformation (Unnullify a)
forall a. DBType a => TypeInformation a
typeInformation


nonEmptyOf :: Sql DBType a => NonEmpty (Expr a) -> Expr (NonEmpty a)
nonEmptyOf :: NonEmpty (Expr a) -> Expr (NonEmpty a)
nonEmptyOf = TypeInformation (Unnullify a)
-> NonEmpty (Expr a) -> Expr (NonEmpty a)
forall a.
TypeInformation (Unnullify a)
-> NonEmpty (Expr a) -> Expr (NonEmpty a)
snonEmptyOf TypeInformation (Unnullify a)
forall a. DBType a => TypeInformation a
typeInformation