diff --git a/src/Rel8.hs b/src/Rel8.hs index 7a94aba0..46ae602c 100644 --- a/src/Rel8.hs +++ b/src/Rel8.hs @@ -158,6 +158,7 @@ module Rel8 , (==.), (/=.), (==?), (/=?) , in_ , boolExpr, caseExpr + , like, ilike -- ** Ordering , DBOrd @@ -318,6 +319,7 @@ import Rel8.Expr.Ord import Rel8.Expr.Order import Rel8.Expr.Serialize import Rel8.Expr.Sequence +import Rel8.Expr.Text ( like, ilike ) import Rel8.Generic.Rel8able ( KRel8able, Rel8able ) import Rel8.Order import Rel8.Query diff --git a/src/Rel8/Expr/Text.hs b/src/Rel8/Expr/Text.hs index 13d406c9..f2a21039 100644 --- a/src/Rel8/Expr/Text.hs +++ b/src/Rel8/Expr/Text.hs @@ -17,6 +17,9 @@ module Rel8.Expr.Text , pgClientEncoding, quoteIdent, quoteLiteral, quoteNullable, regexpReplace , regexpSplitToArray, repeat, replace, reverse, right, rpad, rtrim , splitPart, strpos, substr, translate + + -- * @LIKE@ and @ILIKE@ + , like, ilike ) where @@ -24,7 +27,7 @@ where import Data.Bool ( Bool ) import Data.Int ( Int32 ) import Data.Maybe ( Maybe( Nothing, Just ) ) -import Prelude () +import Prelude ( flip ) -- bytestring import Data.ByteString ( ByteString ) @@ -49,7 +52,7 @@ infixr 6 ++. -- | Matches regular expression, case sensitive --- +-- -- Corresponds to the @~.@ operator. (~.) :: Expr Text -> Expr Text -> Expr Bool (~.) = binaryOperator "~." @@ -273,3 +276,21 @@ substr a b Nothing = function "substr" a b -- | Corresponds to the @translate@ function. translate :: Expr Text -> Expr Text -> Expr Text -> Expr Text translate = function "translate" + + +-- | @like x y@ corresponds to the expression @y LIKE x@. +-- +-- Note that the arguments to @like@ are swapped. This is to aid currying, so +-- you can write expressions like +-- @filter (like "Rel%" . packageName) =<< each haskellPackages@ +like :: Expr Text -> Expr Text -> Expr Bool +like = flip (binaryOperator "LIKE") + + +-- | @ilike x y@ corresponds to the expression @y ILIKE x@. +-- +-- Note that the arguments to @ilike@ are swapped. This is to aid currying, so +-- you can write expressions like +-- @filter (ilike "Rel%" . packageName) =<< each haskellPackages@ +ilike :: Expr Text -> Expr Text -> Expr Bool +ilike = flip (binaryOperator "ILIKE")