on 28aaa76 help sign in
rel8/src/Rel8/Expr/Text.hs
241 lines 5.6 kB history raw
1{-# language DataKinds #-}
3module Rel8.Expr.Text
4 (
5 -- * String concatenation
6 (++.)
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, toAscii, toHex, translate
20 )
21where
23-- base
24import Data.Bool ( Bool )
25import Data.Int ( Int32 )
26import Data.Maybe ( Maybe( Nothing, Just ) )
27import Prelude ()
29-- bytestring
30import Data.ByteString ( ByteString )
32-- rel8
33import Rel8.Expr ( Expr )
34import Rel8.Expr.Function ( binaryOperator, function, nullaryFunction )
35import Rel8.Type.Array1D ( Array1D )
37-- text
38import Data.Text (Text)
41-- | The PostgreSQL string concatenation operator.
42(++.) :: Expr Text -> Expr Text -> Expr Text
43(++.) = binaryOperator "||"
44infixr 6 ++.
47-- * Regular expression operators
49-- See https://www.postgresql.org/docs/9.5/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
52-- | Matches regular expression, case sensitive
53(~.) :: Expr Text -> Expr Text -> Expr Bool
54(~.) = binaryOperator "~."
55infix 2 ~.
58-- | Matches regular expression, case insensitive
59(~*) :: Expr Text -> Expr Text -> Expr Bool
60(~*) = binaryOperator "~*"
61infix 2 ~*
64-- | Does not match regular expression, case sensitive
65(!~) :: Expr Text -> Expr Text -> Expr Bool
66(!~) = binaryOperator "!~"
67infix 2 !~
70-- | Does not match regular expression, case insensitive
71(!~*) :: Expr Text -> Expr Text -> Expr Bool
72(!~*) = binaryOperator "!~*"
73infix 2 !~*
76-- See https://www.postgresql.org/docs/9.5/static/functions-Expr.'PGHtml
78-- * Standard SQL functions
81bitLength :: Expr Text -> Expr Int32
82bitLength = function "bit_length"
85charLength :: Expr Text -> Expr Int32
86charLength = function "char_length"
89lower :: Expr Text -> Expr Text
90lower = function "lower"
93octetLength :: Expr Text -> Expr Int32
94octetLength = function "octet_length"
97upper :: Expr Text -> Expr Text
98upper = function "upper"
101-- * PostgreSQL functions
102ascii :: Expr Text -> Expr Int32
103ascii = function "ascii"
106btrim :: Expr Text -> Maybe (Expr Text) -> Expr Text
107btrim a (Just b) = function "btrim" a b
108btrim a Nothing = function "btrim" a
111chr :: Expr Int32 -> Expr Text
112chr = function "chr"
115convert :: Expr ByteString -> Expr Text -> Expr Text -> Expr ByteString
116convert = function "convert"
119convertFrom :: Expr ByteString -> Expr Text -> Expr Text
120convertFrom = function "convert_from"
123convertTo :: Expr Text -> Expr Text -> Expr ByteString
124convertTo = function "convert_to"
127decode :: Expr Text -> Expr Text -> Expr ByteString
128decode = function "decode"
131encode :: Expr ByteString -> Expr Text -> Expr Text
132encode = function "encode"
135initcap :: Expr Text -> Expr Text
136initcap = function "initcap"
139left :: Expr Text -> Expr Int32 -> Expr Text
140left = function "left"
143length :: Expr Text -> Expr Int32
144length = function "length"
147lengthEncoding :: Expr ByteString -> Expr Text -> Expr Int32
148lengthEncoding = function "length"
151lpad :: Expr Text -> Expr Int32 -> Maybe (Expr Text) -> Expr Text
152lpad a b (Just c) = function "lpad" a b c
153lpad a b Nothing = function "lpad" a b
156ltrim :: Expr Text -> Maybe (Expr Text) -> Expr Text
157ltrim a (Just b) = function "ltrim" a b
158ltrim a Nothing = function "ltrim" a
161md5 :: Expr Text -> Expr Text
162md5 = function "md5"
165pgClientEncoding :: Expr Text
166pgClientEncoding = nullaryFunction "pg_client_encoding"
169quoteIdent :: Expr Text -> Expr Text
170quoteIdent = function "quote_ident"
173quoteLiteral :: Expr Text -> Expr Text
174quoteLiteral = function "quote_literal"
177quoteNullable :: Expr Text -> Expr Text
178quoteNullable = function "quote_nullable"
181regexpReplace :: ()
182 => Expr Text -> Expr Text -> Expr Text -> Maybe (Expr Text) -> Expr Text
183regexpReplace a b c (Just d) = function "regexp_replace" a b c d
184regexpReplace a b c Nothing = function "regexp_replace" a b c
187regexpSplitToArray :: ()
188 => Expr Text -> Expr Text -> Maybe (Expr Text) -> Expr (Array1D Text)
189regexpSplitToArray a b (Just c) = function "regexp_split_to_array" a b c
190regexpSplitToArray a b Nothing = function "regexp_split_to_array" a b
193repeat :: Expr Text -> Expr Int32 -> Expr Text
194repeat = function "repeat"
197replace :: Expr Text -> Expr Text -> Expr Text -> Expr Text
198replace = function "replace"
201reverse :: Expr Text -> Expr Text
202reverse = function "reverse"
205right :: Expr Text -> Expr Int32 -> Expr Text
206right = function "right"
209rpad :: Expr Text -> Expr Int32 -> Maybe (Expr Text) -> Expr Text
210rpad a b (Just c) = function "rpad" a b c
211rpad a b Nothing = function "rpad" a b
214rtrim :: Expr Text -> Maybe (Expr Text) -> Expr Text
215rtrim a (Just b) = function "rtrim" a b
216rtrim a Nothing = function "rtrim" a
219splitPart :: Expr Text -> Expr Text -> Expr Int32 -> Expr Text
220splitPart = function "split_part"
223strpos :: Expr Text -> Expr Text -> Expr Int32
224strpos = function "strpos"
227substr :: Expr Text -> Expr Int32 -> Maybe (Expr Int32) -> Expr Text
228substr a b (Just c) = function "substr" a b c
229substr a b Nothing = function "substr" a b
232toAscii :: Expr Text -> Expr Text -> Expr Text
233toAscii = function "toAscii"
236toHex :: Expr Int32 -> Expr Text
237toHex = function "toHex"
240translate :: Expr Text -> Expr Text -> Expr Text -> Expr Text
241translate = function "translate"