New justList function.

This commit is contained in:
Felipe Lessa 2015-08-05 15:41:10 -03:00
parent 9dbdcb53fa
commit 871708987d
3 changed files with 11 additions and 1 deletions

View File

@ -48,7 +48,7 @@ module Database.Esqueleto
, min_, max_, sum_, avg_, castNum, castNumM
, coalesce, coalesceDefault
, lower_, like, ilike, (%), concat_, (++.)
, subList_select, subList_selectDistinct, valList
, subList_select, subList_selectDistinct, valList, justList
, in_, notIn, exists, notExists
, set, (=.), (+=.), (-=.), (*=.), (/=.)
, case_ )

View File

@ -427,6 +427,13 @@ class (Functor query, Applicative query, Monad query) =>
-- | Lift a list of constant value from Haskell-land to the query.
valList :: PersistField typ => [typ] -> expr (ValueList typ)
-- | Same as 'just' but for 'ValueList'. Most of the time you
-- won't need it, though, because you can use 'just' from
-- inside 'subList_select' or 'Just' from inside 'valList'.
--
-- /Since: 2.2.12/
justList :: expr (ValueList typ) -> expr (ValueList (Maybe typ))
-- | @IN@ operator.
in_ :: PersistField typ => expr (Value typ) -> expr (ValueList typ) -> expr (Value Bool)

View File

@ -496,6 +496,9 @@ instance Esqueleto SqlQuery SqlExpr SqlBackend where
valList vals = EList $ ERaw Parens $ const ( uncommas ("?" <$ vals)
, map toPersistValue vals )
justList EEmptyList = EEmptyList
justList (EList v) = EList (just v)
v `in_` e = ifNotEmptyList e False $ unsafeSqlBinOp " IN " v (veryUnsafeCoerceSqlExprValueList e)
v `notIn` e = ifNotEmptyList e True $ unsafeSqlBinOp " NOT IN " v (veryUnsafeCoerceSqlExprValueList e)