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