New function unsafeSqlValue.
This commit is contained in:
parent
ef771c6eda
commit
6f1cbe36a7
@ -23,6 +23,7 @@ module Database.Esqueleto.Internal.Sql
|
|||||||
, update
|
, update
|
||||||
-- * The guts
|
-- * The guts
|
||||||
, unsafeSqlBinOp
|
, unsafeSqlBinOp
|
||||||
|
, unsafeSqlValue
|
||||||
, rawSelectSource
|
, rawSelectSource
|
||||||
, runSource
|
, runSource
|
||||||
, rawExecute
|
, rawExecute
|
||||||
@ -272,8 +273,8 @@ instance Esqueleto SqlQuery SqlExpr SqlPersist where
|
|||||||
|
|
||||||
isNothing (ERaw p f) = ERaw Never $ first ((<> " IS NULL") . parensM p) . f
|
isNothing (ERaw p f) = ERaw Never $ first ((<> " IS NULL") . parensM p) . f
|
||||||
just (ERaw p f) = ERaw p f
|
just (ERaw p f) = ERaw p f
|
||||||
nothing = ERaw Never $ \_ -> ("NULL", mempty)
|
nothing = unsafeSqlValue "NULL"
|
||||||
countRows = ERaw Never $ \_ -> ("COUNT(*)", mempty)
|
countRows = unsafeSqlValue "COUNT(*)"
|
||||||
|
|
||||||
not_ (ERaw p f) = ERaw Never $ \esc -> let (b, vals) = f esc
|
not_ (ERaw p f) = ERaw Never $ \esc -> let (b, vals) = f esc
|
||||||
in ("NOT " <> parensM p b, vals)
|
in ("NOT " <> parensM p b, vals)
|
||||||
@ -342,6 +343,14 @@ unsafeSqlBinOp op (ERaw p1 f1) (ERaw p2 f2) = ERaw Parens f
|
|||||||
(b2, vals2) = f2 esc
|
(b2, vals2) = f2 esc
|
||||||
in ( parensM p1 b1 <> op <> parensM p2 b2
|
in ( parensM p1 b1 <> op <> parensM p2 b2
|
||||||
, vals1 <> vals2 )
|
, vals1 <> vals2 )
|
||||||
|
{-# INLINE unsafeSqlBinOp #-}
|
||||||
|
|
||||||
|
|
||||||
|
-- | (Internal) A raw SQL value. The same warning from
|
||||||
|
-- 'unsafeSqlBinOp' applies to this function as well.
|
||||||
|
unsafeSqlValue :: TLB.Builder -> SqlExpr (Value a)
|
||||||
|
unsafeSqlValue v = ERaw Never $ \_ -> (v, mempty)
|
||||||
|
{-# INLINE unsafeSqlValue #-}
|
||||||
|
|
||||||
|
|
||||||
-- | (Internal) Coerce a type of a 'SqlExpr (Value a)' into
|
-- | (Internal) Coerce a type of a 'SqlExpr (Value a)' into
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user