1{-# language DataKinds #-}
5 -- * String concatenation
8 -- * Regular expression operators
9 , (~.), (~*), (!~), (!~*)
11 -- * Standard SQL functions
12 , bitLength, charLength, lower, octetLength, upper
14 -- * PostgreSQL functions
15 , ascii, btrim, chr, convert, convertFrom, convertTo, decode, encode
16 , initcap, left, length, lengthEncoding, lpad, ltrim, md5
17 , pgClientEncoding, quoteIdent, quoteLiteral, quoteNullable, regexpReplace
18 , regexpSplitToArray, repeat, replace, reverse, right, rpad, rtrim
19 , splitPart, strpos, substr, translate
21 -- * @LIKE@ and @ILIKE@
27import Data.Bool ( Bool )
28import Data.Int ( Int32 )
29import Data.Maybe ( Maybe( Nothing, Just ) )
30import Prelude ( flip )
33import Data.ByteString ( ByteString )
36import Rel8.Expr ( Expr )
37import Rel8.Expr.Function ( binaryOperator, function, nullaryFunction )
40import Data.Text (Text)
43-- | The PostgreSQL string concatenation operator.
44(++.) :: Expr Text -> Expr Text -> Expr Text
45(++.) = binaryOperator "||"
49-- * Regular expression operators
51-- See https://www.postgresql.org/docs/9.5/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
54-- | Matches regular expression, case sensitive
56-- Corresponds to the @~.@ operator.
57(~.) :: Expr Text -> Expr Text -> Expr Bool
58(~.) = binaryOperator "~."
62-- | Matches regular expression, case insensitive
64-- Corresponds to the @~*@ operator.
65(~*) :: Expr Text -> Expr Text -> Expr Bool
66(~*) = binaryOperator "~*"
70-- | Does not match regular expression, case sensitive
72-- Corresponds to the @!~@ operator.
73(!~) :: Expr Text -> Expr Text -> Expr Bool
74(!~) = binaryOperator "!~"
78-- | Does not match regular expression, case insensitive
80-- Corresponds to the @!~*@ operator.
81(!~*) :: Expr Text -> Expr Text -> Expr Bool
82(!~*) = binaryOperator "!~*"
86-- See https://www.postgresql.org/docs/9.5/static/functions-Expr.'PGHtml
88-- * Standard SQL functions
91-- | Corresponds to the @bit_length@ function.
92bitLength :: Expr Text -> Expr Int32
93bitLength = function "bit_length"
96-- | Corresponds to the @char_length@ function.
97charLength :: Expr Text -> Expr Int32
98charLength = function "char_length"
101-- | Corresponds to the @lower@ function.
102lower :: Expr Text -> Expr Text
103lower = function "lower"
106-- | Corresponds to the @octet_length@ function.
107octetLength :: Expr Text -> Expr Int32
108octetLength = function "octet_length"
111-- | Corresponds to the @upper@ function.
112upper :: Expr Text -> Expr Text
113upper = function "upper"
116-- | Corresponds to the @ascii@ function.
117ascii :: Expr Text -> Expr Int32
118ascii = function "ascii"
121-- | Corresponds to the @btrim@ function.
122btrim :: Expr Text -> Maybe (Expr Text) -> Expr Text
123btrim a (Just b) = function "btrim" a b
124btrim a Nothing = function "btrim" a
127-- | Corresponds to the @chr@ function.
128chr :: Expr Int32 -> Expr Text
132-- | Corresponds to the @convert@ function.
133convert :: Expr ByteString -> Expr Text -> Expr Text -> Expr ByteString
134convert = function "convert"
137-- | Corresponds to the @convert_from@ function.
138convertFrom :: Expr ByteString -> Expr Text -> Expr Text
139convertFrom = function "convert_from"
142-- | Corresponds to the @convert_to@ function.
143convertTo :: Expr Text -> Expr Text -> Expr ByteString
144convertTo = function "convert_to"
147-- | Corresponds to the @decode@ function.
148decode :: Expr Text -> Expr Text -> Expr ByteString
149decode = function "decode"
152-- | Corresponds to the @encode@ function.
153encode :: Expr ByteString -> Expr Text -> Expr Text
154encode = function "encode"
157-- | Corresponds to the @initcap@ function.
158initcap :: Expr Text -> Expr Text
159initcap = function "initcap"
162-- | Corresponds to the @left@ function.
163left :: Expr Text -> Expr Int32 -> Expr Text
164left = function "left"
167-- | Corresponds to the @length@ function.
168length :: Expr Text -> Expr Int32
169length = function "length"
172-- | Corresponds to the @length@ function.
173lengthEncoding :: Expr ByteString -> Expr Text -> Expr Int32
174lengthEncoding = function "length"
177-- | Corresponds to the @lpad@ function.
178lpad :: Expr Text -> Expr Int32 -> Maybe (Expr Text) -> Expr Text
179lpad a b (Just c) = function "lpad" a b c
180lpad a b Nothing = function "lpad" a b
183-- | Corresponds to the @ltrim@ function.
184ltrim :: Expr Text -> Maybe (Expr Text) -> Expr Text
185ltrim a (Just b) = function "ltrim" a b
186ltrim a Nothing = function "ltrim" a
189-- | Corresponds to the @md5@ function.
190md5 :: Expr Text -> Expr Text
194-- | Corresponds to the @pg_client_encoding()@ expression.
195pgClientEncoding :: Expr Text
196pgClientEncoding = nullaryFunction "pg_client_encoding"
199-- | Corresponds to the @quote_ident@ function.
200quoteIdent :: Expr Text -> Expr Text
201quoteIdent = function "quote_ident"
204-- | Corresponds to the @quote_literal@ function.
205quoteLiteral :: Expr Text -> Expr Text
206quoteLiteral = function "quote_literal"
209-- | Corresponds to the @quote_nullable@ function.
210quoteNullable :: Expr Text -> Expr Text
211quoteNullable = function "quote_nullable"
214-- | Corresponds to the @regexp_replace@ function.
216 => Expr Text -> Expr Text -> Expr Text -> Maybe (Expr Text) -> Expr Text
217regexpReplace a b c (Just d) = function "regexp_replace" a b c d
218regexpReplace a b c Nothing = function "regexp_replace" a b c
221-- | Corresponds to the @regexp_split_to_array@ function.
222regexpSplitToArray :: ()
223 => Expr Text -> Expr Text -> Maybe (Expr Text) -> Expr [Text]
224regexpSplitToArray a b (Just c) = function "regexp_split_to_array" a b c
225regexpSplitToArray a b Nothing = function "regexp_split_to_array" a b
228-- | Corresponds to the @repeat@ function.
229repeat :: Expr Text -> Expr Int32 -> Expr Text
230repeat = function "repeat"
233-- | Corresponds to the @replace@ function.
234replace :: Expr Text -> Expr Text -> Expr Text -> Expr Text
235replace = function "replace"
238-- | Corresponds to the @reverse@ function.
239reverse :: Expr Text -> Expr Text
240reverse = function "reverse"
243-- | Corresponds to the @right@ function.
244right :: Expr Text -> Expr Int32 -> Expr Text
245right = function "right"
248-- | Corresponds to the @rpad@ function.
249rpad :: Expr Text -> Expr Int32 -> Maybe (Expr Text) -> Expr Text
250rpad a b (Just c) = function "rpad" a b c
251rpad a b Nothing = function "rpad" a b
254-- | Corresponds to the @rtrim@ function.
255rtrim :: Expr Text -> Maybe (Expr Text) -> Expr Text
256rtrim a (Just b) = function "rtrim" a b
257rtrim a Nothing = function "rtrim" a
260-- | Corresponds to the @split_part@ function.
261splitPart :: Expr Text -> Expr Text -> Expr Int32 -> Expr Text
262splitPart = function "split_part"
265-- | Corresponds to the @strpos@ function.
266strpos :: Expr Text -> Expr Text -> Expr Int32
267strpos = function "strpos"
270-- | Corresponds to the @substr@ function.
271substr :: Expr Text -> Expr Int32 -> Maybe (Expr Int32) -> Expr Text
272substr a b (Just c) = function "substr" a b c
273substr a b Nothing = function "substr" a b
276-- | Corresponds to the @translate@ function.
277translate :: Expr Text -> Expr Text -> Expr Text -> Expr Text
278translate = function "translate"
281-- | @like x y@ corresponds to the expression @y LIKE x@.
283-- Note that the arguments to @like@ are swapped. This is to aid currying, so
284-- you can write expressions like
285-- @filter (like "Rel%" . packageName) =<< each haskellPackages@
286like :: Expr Text -> Expr Text -> Expr Bool
287like = flip (binaryOperator "LIKE")
290-- | @ilike x y@ corresponds to the expression @y ILIKE x@.
292-- Note that the arguments to @ilike@ are swapped. This is to aid currying, so
293-- you can write expressions like
294-- @filter (ilike "Rel%" . packageName) =<< each haskellPackages@
295ilike :: Expr Text -> Expr Text -> Expr Bool
296ilike = flip (binaryOperator "ILIKE")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list