on dev help sign in
docs!
622b021Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+1−1
@@ -1,7 +1,7 @@
1{-|
1{-|
2Module: Squeal.PostgreSQL.Expression
2Module: Squeal.PostgreSQL.Expression
3Description: Squeal expressions
3Description: Squeal expressions
4−Copyright: (c) Eitan Chatav, 2017
4+Copyright: (c) Eitan Chatav, 2019
5Maintainer: eitan@morphism.tech
5Maintainer: eitan@morphism.tech
6Stability: experimental
6Stability: experimental
7
7
squeal-postgresql/src/Squeal/PostgreSQL/Expression/TextSearch.hs+51
@@ -1,3 +1,13 @@
1+{-|
2+Module: Squeal.PostgreSQL.Expression.TextSearch
3+Description: Text search expressions
4+Copyright: (c) Eitan Chatav, 2019
5+Maintainer: eitan@morphism.tech
6+Stability: experimental
7+
8+Text Search Functions and Operators
9+-}
10+
1{-# LANGUAGE
11{-# LANGUAGE
2 DataKinds
12 DataKinds
3 , OverloadedStrings
13 , OverloadedStrings
@@ -32,75 +42,116 @@ import Squeal.PostgreSQL.Expression
32import Squeal.PostgreSQL.List
42import Squeal.PostgreSQL.List
33import Squeal.PostgreSQL.Schema
43import Squeal.PostgreSQL.Schema
34
44
45+-- | `Squeal.PostgreSQL.Expression.Type.tsvector` matches tsquery ?
35(@@) :: Operator (null 'PGtsvector) (null 'PGtsquery) ('Null 'PGbool)
46(@@) :: Operator (null 'PGtsvector) (null 'PGtsquery) ('Null 'PGbool)
36(@@) = unsafeBinaryOp "@@"
47(@@) = unsafeBinaryOp "@@"
37
48
49+-- | AND `Squeal.PostgreSQL.Expression.Type.tsquery`s together
38(.&) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
50(.&) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
39(.&) = unsafeBinaryOp "&&"
51(.&) = unsafeBinaryOp "&&"
40
52
53+-- | OR `Squeal.PostgreSQL.Expression.Type.tsquery`s together
41(.|) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
54(.|) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
42(.|) = unsafeBinaryOp "||"
55(.|) = unsafeBinaryOp "||"
43
56
57+-- | negate a `Squeal.PostgreSQL.Expression.Type.tsquery`
44(.!) :: null 'PGtsquery :--> null 'PGtsquery
58(.!) :: null 'PGtsquery :--> null 'PGtsquery
45(.!) = unsafeUnaryOpL "!!"
59(.!) = unsafeUnaryOpL "!!"
46
60
61+-- | `Squeal.PostgreSQL.Expression.Type.tsquery` followed by
62+-- `Squeal.PostgreSQL.Expression.Type.tsquery`
47(<->) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
63(<->) :: Operator (null 'PGtsquery) (null 'PGtsquery) (null 'PGtsquery)
48(<->) = unsafeBinaryOp "<->"
64(<->) = unsafeBinaryOp "<->"
49
65
66+-- | convert array of lexemes to `Squeal.PostgreSQL.Expression.Type.tsvector`
50arrayToTSvector
67arrayToTSvector
51 :: null ('PGvararray ('NotNull 'PGtext))
68 :: null ('PGvararray ('NotNull 'PGtext))
52 :--> null 'PGtsvector
69 :--> null 'PGtsvector
53arrayToTSvector = unsafeFunction "array_to_tsvector"
70arrayToTSvector = unsafeFunction "array_to_tsvector"
54
71
72+-- | number of lexemes in `Squeal.PostgreSQL.Expression.Type.tsvector`
55tsvectorLength :: null 'PGtsvector :--> null 'PGint4
73tsvectorLength :: null 'PGtsvector :--> null 'PGint4
56tsvectorLength = unsafeFunction "length"
74tsvectorLength = unsafeFunction "length"
57
75
76+-- | number of lexemes plus operators in `Squeal.PostgreSQL.Expression.Type.tsquery`
58numnode :: null 'PGtsquery :--> null 'PGint4
77numnode :: null 'PGtsquery :--> null 'PGint4
59numnode = unsafeFunction "numnode"
78numnode = unsafeFunction "numnode"
60
79
80+-- | produce `Squeal.PostgreSQL.Expression.Type.tsquery` ignoring punctuation
61plainToTSquery :: null 'PGtext :--> null 'PGtsquery
81plainToTSquery :: null 'PGtext :--> null 'PGtsquery
62plainToTSquery = unsafeFunction "plainto_tsquery"
82plainToTSquery = unsafeFunction "plainto_tsquery"
63
83
84+-- | produce `Squeal.PostgreSQL.Expression.Type.tsquery` that searches for a phrase,
85+-- ignoring punctuation
64phraseToTSquery :: null 'PGtext :--> null 'PGtsquery
86phraseToTSquery :: null 'PGtext :--> null 'PGtsquery
65phraseToTSquery = unsafeFunction "phraseto_tsquery"
87phraseToTSquery = unsafeFunction "phraseto_tsquery"
66
88
89+-- | produce `Squeal.PostgreSQL.Expression.Type.tsquery` from a web search style query
67websearchToTSquery :: null 'PGtext :--> null 'PGtsquery
90websearchToTSquery :: null 'PGtext :--> null 'PGtsquery
68websearchToTSquery = unsafeFunction "websearch_to_tsquery"
91websearchToTSquery = unsafeFunction "websearch_to_tsquery"
69
92
93+-- | get indexable part of a `Squeal.PostgreSQL.Expression.Type.tsquery`
70queryTree :: null 'PGtsquery :--> null 'PGtext
94queryTree :: null 'PGtsquery :--> null 'PGtext
71queryTree = unsafeFunction "query_tree"
95queryTree = unsafeFunction "query_tree"
72
96
97+-- | normalize words and convert to `Squeal.PostgreSQL.Expression.Type.tsquery`
73toTSquery :: null 'PGtext :--> null 'PGtsquery
98toTSquery :: null 'PGtext :--> null 'PGtsquery
74toTSquery = unsafeFunction "to_tsquery"
99toTSquery = unsafeFunction "to_tsquery"
75
100
101+-- | reduce document text to `Squeal.PostgreSQL.Expression.Type.tsvector`
76toTSvector
102toTSvector
77 :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
103 :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
78 => null ty :--> null 'PGtsvector
104 => null ty :--> null 'PGtsvector
79toTSvector = unsafeFunction "to_tsvector"
105toTSvector = unsafeFunction "to_tsvector"
80
106
107+-- | assign weight to each element of `Squeal.PostgreSQL.Expression.Type.tsvector`
81setWeight
108setWeight
82 :: FunctionN '[null 'PGtsvector, null ('PGchar 1)] (null 'PGtsvector)
109 :: FunctionN '[null 'PGtsvector, null ('PGchar 1)] (null 'PGtsvector)
83setWeight = unsafeFunctionN "set_weight"
110setWeight = unsafeFunctionN "set_weight"
84
111
112+-- | remove positions and weights from `Squeal.PostgreSQL.Expression.Type.tsvector`
85strip :: null 'PGtsvector :--> null 'PGtsvector
113strip :: null 'PGtsvector :--> null 'PGtsvector
86strip = unsafeFunction "strip"
114strip = unsafeFunction "strip"
87
115
116+-- | @jsonToTSvector (document *: filter)@
117+-- reduce each value in the document, specified by filter to a `Squeal.PostgreSQL.Expression.Type.tsvector`,
118+-- and then concatenate those in document order to produce a single `Squeal.PostgreSQL.Expression.Type.tsvector`.
119+-- filter is a `Squeal.PostgreSQL.Expression.Type.json` array, that enumerates what kind of elements
120+-- need to be included into the resulting `Squeal.PostgreSQL.Expression.Type.tsvector`.
121+-- Possible values for filter are "string" (to include all string values),
122+-- "numeric" (to include all numeric values in the string format),
123+-- "boolean" (to include all Boolean values in the string format "true"/"false"),
124+-- "key" (to include all keys) or "all" (to include all above).
125+-- These values can be combined together to include, e.g. all string and numeric values.
88jsonToTSvector :: FunctionN '[null 'PGjson, null 'PGjson] (null 'PGtsvector)
126jsonToTSvector :: FunctionN '[null 'PGjson, null 'PGjson] (null 'PGtsvector)
89jsonToTSvector = unsafeFunctionN "json_to_tsvector"
127jsonToTSvector = unsafeFunctionN "json_to_tsvector"
90
128
129+-- | @jsonbToTSvector (document *: filter)@
130+-- reduce each value in the document, specified by filter to a `Squeal.PostgreSQL.Expression.Type.tsvector`,
131+-- and then concatenate those in document order to produce a single `Squeal.PostgreSQL.Expression.Type.tsvector`.
132+-- filter is a `Squeal.PostgreSQL.Expression.Type.jsonb` array, that enumerates what kind of elements
133+-- need to be included into the resulting `Squeal.PostgreSQL.Expression.Type.tsvector`.
134+-- Possible values for filter are "string" (to include all string values),
135+-- "numeric" (to include all numeric values in the string format),
136+-- "boolean" (to include all Boolean values in the string format "true"/"false"),
137+-- "key" (to include all keys) or "all" (to include all above).
138+-- These values can be combined together to include, e.g. all string and numeric values.
91jsonbToTSvector :: FunctionN '[null 'PGjsonb, null 'PGjsonb] (null 'PGtsvector)
139jsonbToTSvector :: FunctionN '[null 'PGjsonb, null 'PGjsonb] (null 'PGtsvector)
92jsonbToTSvector = unsafeFunctionN "jsonb_to_tsvector"
140jsonbToTSvector = unsafeFunctionN "jsonb_to_tsvector"
93
141
142+-- | remove given lexeme from `Squeal.PostgreSQL.Expression.Type.tsvector`
94tsDelete :: FunctionN
143tsDelete :: FunctionN
95 '[null 'PGtsvector, null ('PGvararray ('NotNull 'PGtext))]
144 '[null 'PGtsvector, null ('PGvararray ('NotNull 'PGtext))]
96 (null 'PGtsvector)
145 (null 'PGtsvector)
97tsDelete = unsafeFunctionN "ts_delete"
146tsDelete = unsafeFunctionN "ts_delete"
98
147
148+-- | select only elements with given weights from `Squeal.PostgreSQL.Expression.Type.tsvector`
99tsFilter :: FunctionN
149tsFilter :: FunctionN
100 '[null 'PGtsvector, null ('PGvararray ('NotNull ('PGchar 1)))]
150 '[null 'PGtsvector, null ('PGvararray ('NotNull ('PGchar 1)))]
101 (null 'PGtsvector)
151 (null 'PGtsvector)
102tsFilter = unsafeFunctionN "ts_filter"
152tsFilter = unsafeFunctionN "ts_filter"
103
153
154+-- | display a `Squeal.PostgreSQL.Expression.Type.tsquery` match
104tsHeadline
155tsHeadline
105 :: document `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
156 :: document `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
106 => FunctionN '[null document, null 'PGtsquery] (null 'PGtext)
157 => FunctionN '[null document, null 'PGtsquery] (null 'PGtext)
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Time.hs+11
@@ -1,3 +1,13 @@
1+{-|
2+Module: Squeal.PostgreSQL.Expression.Time
3+Description: Date/Time expressions
4+Copyright: (c) Eitan Chatav, 2019
5+Maintainer: eitan@morphism.tech
6+Stability: experimental
7+
8+Date/Time Functions and Operators
9+-}
10+
1{-# LANGUAGE
11{-# LANGUAGE
2 DataKinds
12 DataKinds
3 , DeriveGeneric
13 , DeriveGeneric
@@ -156,6 +166,7 @@ infixl 6 +!
156infixl 6 !-
166infixl 6 !-
157infixl 6 !-!
167infixl 6 !-!
158
168
169+-- | A `TimeUnit` to use in `interval_` construction.
159data TimeUnit
170data TimeUnit
160 = Years | Months | Weeks | Days
171 = Years | Months | Weeks | Days
161 | Hours | Minutes | Seconds
172 | Hours | Minutes | Seconds
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Type.hs+12
@@ -1,3 +1,13 @@
1+{-|
2+Module: Squeal.PostgreSQL.Expression
3+Description: Type expressions
4+Copyright: (c) Eitan Chatav, 2019
5+Maintainer: eitan@morphism.tech
6+Stability: experimental
7+
8+Type expressions.
9+-}
10+
1{-# LANGUAGE
11{-# LANGUAGE
2 AllowAmbiguousTypes
12 AllowAmbiguousTypes
3 , DataKinds
13 , DataKinds
@@ -230,8 +240,10 @@ fixarray ty = UnsafeTypeExpression $
230 $ SOP.hcmap (SOP.Proxy @KnownNat)
240 $ SOP.hcmap (SOP.Proxy @KnownNat)
231 (K . fromString . show . natVal)
241 (K . fromString . show . natVal)
232 (SOP.hpure SOP.Proxy :: SOP.NP SOP.Proxy ns)
242 (SOP.hpure SOP.Proxy :: SOP.NP SOP.Proxy ns)
243+-- | text search query
233tsvector :: TypeExpression schemas (null 'PGtsvector)
244tsvector :: TypeExpression schemas (null 'PGtsvector)
234tsvector = UnsafeTypeExpression "tsvector"
245tsvector = UnsafeTypeExpression "tsvector"
246+-- | text search document
235tsquery :: TypeExpression schemas (null 'PGtsquery)
247tsquery :: TypeExpression schemas (null 'PGtsquery)
236tsquery = UnsafeTypeExpression "tsquery"
248tsquery = UnsafeTypeExpression "tsquery"
237
249