commit
43de402a54
@ -46,7 +46,7 @@ module Database.Esqueleto
|
||||
, random_, round_, ceiling_, floor_
|
||||
, min_, max_, sum_, avg_, lower_
|
||||
, coalesce, coalesceDefault
|
||||
, like, (%), concat_, (++.)
|
||||
, like, ilike, (%), concat_, (++.)
|
||||
, subList_select, subList_selectDistinct, valList
|
||||
, in_, notIn, exists, notExists
|
||||
, set, (=.), (+=.), (-=.), (*=.), (/=.)
|
||||
|
||||
@ -276,6 +276,9 @@ class (Functor query, Applicative query, Monad query) =>
|
||||
|
||||
-- | @LIKE@ operator.
|
||||
like :: (PersistField s, IsString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool)
|
||||
-- | @ILIKE@ operator (case-insensitive @LIKE@).
|
||||
-- Supported by PostgreSQL only.
|
||||
ilike :: (PersistField s, IsString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool)
|
||||
-- | The string @'%'@. May be useful while using 'like' and
|
||||
-- concatenation ('concat_' or '++.', depending on your
|
||||
-- database). Note that you always to type the parenthesis,
|
||||
@ -391,7 +394,7 @@ infixl 6 +., -.
|
||||
infixr 5 ++.
|
||||
infix 4 ==., >=., >., <=., <., !=.
|
||||
infixr 3 &&., =., +=., -=., *=., /=.
|
||||
infixr 2 ||., `like`
|
||||
infixr 2 ||., `like`, `ilike`
|
||||
infixl 2 `InnerJoin`, `CrossJoin`, `LeftOuterJoin`, `RightOuterJoin`, `FullOuterJoin`
|
||||
|
||||
-- | Syntax sugar for 'case_'.
|
||||
|
||||
@ -445,6 +445,7 @@ instance Esqueleto SqlQuery SqlExpr SqlBackend where
|
||||
coalesceDefault exprs = unsafeSqlFunctionParens "COALESCE" . (exprs ++) . return . just
|
||||
|
||||
like = unsafeSqlBinOp " LIKE "
|
||||
ilike = unsafeSqlBinOp " ILIKE "
|
||||
(%) = unsafeSqlValue "'%'"
|
||||
concat_ = unsafeSqlFunction "CONCAT"
|
||||
(++.) = unsafeSqlBinOp " || "
|
||||
|
||||
17
test/Test.hs
17
test/Test.hs
@ -854,7 +854,7 @@ main = do
|
||||
#endif
|
||||
#endif
|
||||
|
||||
describe "text functions" $
|
||||
describe "text functions" $ do
|
||||
it "like, (%) and (++.) work on a simple example" $
|
||||
run $ do
|
||||
[p1e, p2e, p3e, p4e] <- mapM insert' [p1, p2, p3, p4]
|
||||
@ -869,6 +869,21 @@ main = do
|
||||
nameContains "i" [p4e, p3e]
|
||||
nameContains "iv" [p4e]
|
||||
|
||||
#if defined(WITH_POSTGRESQL)
|
||||
it "ilike, (%) and (++.) work on a simple example on PostgreSQL" $
|
||||
run $ do
|
||||
[p1e, p2e, p3e, p4e, p5e] <- mapM insert' [p1, p2, p3, p4, p5]
|
||||
let nameContains t expected = do
|
||||
ret <- select $
|
||||
from $ \p -> do
|
||||
where_ (p ^. PersonName `ilike` (%) ++. val t ++. (%))
|
||||
orderBy [asc (p ^. PersonName)]
|
||||
return p
|
||||
liftIO $ ret `shouldBe` expected
|
||||
nameContains "mi" [p3e, p5e]
|
||||
nameContains "JOHN" [p1e]
|
||||
#endif
|
||||
|
||||
describe "delete" $
|
||||
it "works on a simple example" $
|
||||
run $ do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user