on dev help sign in
function changes
commit40ad89af29075d3dc2352477293a8597210cd59d authorEitan Chatav <eitan@EEM109LMBP-1.local> dateWed 25 Sep 2019, 13:53 (7 years ago) parentc42b09d
15 files changed+128−132
RELEASE NOTES.md+2−2 squeal-postgresql/src/Squeal/PostgreSQL/Definition/Function.hs+11−11 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+10−10 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Collection.hs+2−2 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Comparison.hs+6−6 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Json.hs+27−34 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Logic.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Math.hs+4−6 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Null.hs+4−4 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Range.hs+8−9 squeal-postgresql/src/Squeal/PostgreSQL/Expression/SetOf.hs+22−10 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Text.hs+3−3 squeal-postgresql/src/Squeal/PostgreSQL/Expression/TextSearch.hs+19−20 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Time.hs+7−12 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−2
RELEASE NOTES.md+2−2
@@ -138,11 +138,11 @@ type Expr x
138138 . Expression outer commons grp schemas params from x
139139```
140140
141−There is also a function type `(:-->)`, which is a subtype of the usual Haskell function
141+There is also a function type `(-->)`, which is a subtype of the usual Haskell function
142142type `(->)`.
143143
144144```Haskell
145−type (:-->) x y
145+type (-->) x y
146146 = forall outer commons grp schemas params from
147147 . Expression outer commons grp schemas params from x
148148 -> Expression outer commons grp schemas params from y
squeal-postgresql/src/Squeal/PostgreSQL/Definition/Function.hs+11−11
@@ -73,7 +73,7 @@ createFunction
7373 -> NP (TypeExpression schemas) args
7474 -> TypeExpression schemas ret
7575 -> FunctionDefinition schemas args ('Returns ret)
76− -> Definition schemas (Alter sch (Create fun ('Function (args '::--> 'Returns ret)) schema) schemas)
76+ -> Definition schemas (Alter sch (Create fun ('Function (args :=> 'Returns ret)) schema) schemas)
7777createFunction fun args ret fundef = UnsafeDefinition $
7878 "CREATE" <+> "FUNCTION" <+> renderSQL fun
7979 <+> parenthesized (renderCommaSeparated renderSQL args)
@@ -87,7 +87,7 @@ createOrReplaceFunction
8787 -> NP (TypeExpression schemas) args
8888 -> TypeExpression schemas ret
8989 -> FunctionDefinition schemas args ('Returns ret)
90− -> Definition schemas (Alter sch (CreateOrReplace fun ('Function (args '::--> 'Returns ret)) schema) schemas)
90+ -> Definition schemas (Alter sch (CreateOrReplace fun ('Function (args :=> 'Returns ret)) schema) schemas)
9191createOrReplaceFunction fun args ret fundef = UnsafeDefinition $
9292 "CREATE" <+> "OR" <+> "REPLACE" <+> "FUNCTION" <+> renderSQL fun
9393 <+> parenthesized (renderCommaSeparated renderSQL args)
@@ -115,7 +115,7 @@ createSetFunction
115115 -> NP (TypeExpression schemas) args
116116 -> NP (Aliased (TypeExpression schemas)) rets
117117 -> FunctionDefinition schemas args ('ReturnsTable rets)
118− -> Definition schemas (Alter sch (Create fun ('Function (args '::--> 'ReturnsTable rets)) schema) schemas)
118+ -> Definition schemas (Alter sch (Create fun ('Function (args :=> 'ReturnsTable rets)) schema) schemas)
119119createSetFunction fun args rets fundef = UnsafeDefinition $
120120 "CREATE" <+> "FUNCTION" <+> renderSQL fun
121121 <+> parenthesized (renderCommaSeparated renderSQL args)
@@ -128,14 +128,14 @@ createSetFunction fun args rets fundef = UnsafeDefinition $
128128
129129createOrReplaceSetFunction
130130 :: ( Has sch schemas schema
131− , Has fun schema ('Function (args0 '::--> ret0))
131+ , Has fun schema ('Function (args0 :=> ret0))
132132 , SOP.SListI args
133133 , SOP.SListI rets )
134134 => QualifiedAlias sch fun
135135 -> NP (TypeExpression schemas) args
136136 -> NP (Aliased (TypeExpression schemas)) rets
137137 -> FunctionDefinition schemas args ('ReturnsTable rets)
138− -> Definition schemas (Alter sch (CreateOrReplace fun ('Function (args '::--> 'ReturnsTable rets)) schema) schemas)
138+ -> Definition schemas (Alter sch (CreateOrReplace fun ('Function (args :=> 'ReturnsTable rets)) schema) schemas)
139139createOrReplaceSetFunction fun args rets fundef = UnsafeDefinition $
140140 "CREATE" <+> "OR" <+> "REPLACE" <+> "FUNCTION" <+> renderSQL fun
141141 <+> parenthesized (renderCommaSeparated renderSQL args)
@@ -149,9 +149,9 @@ createOrReplaceSetFunction fun args rets fundef = UnsafeDefinition $
149149createBinaryOp
150150 :: forall op fun sch schemas schema x y z.
151151 ( Has sch schemas schema
152− , Has fun schema ('Function ('[x,y] '::--> 'Returns z))
152+ , Has fun schema ('Function ('[x,y] :=> 'Returns z))
153153 , KnownSymbol op )
154− => Alias fun
154+ => QualifiedAlias sch fun
155155 -> TypeExpression schemas x
156156 -> TypeExpression schemas y
157157 -> Definition schemas
@@ -168,9 +168,9 @@ createBinaryOp fun x y = UnsafeDefinition $
168168createLeftOp
169169 :: forall op fun sch schemas schema x y.
170170 ( Has sch schemas schema
171− , Has fun schema ('Function ('[x] '::--> 'Returns y))
171+ , Has fun schema ('Function ('[x] :=> 'Returns y))
172172 , KnownSymbol op )
173− => Alias fun
173+ => QualifiedAlias sch fun
174174 -> TypeExpression schemas x
175175 -> Definition schemas
176176 (Alter sch (Create op ('Operator ('LeftOp x y)) schema) schemas)
@@ -185,9 +185,9 @@ createLeftOp fun x = UnsafeDefinition $
185185createRightOp
186186 :: forall op fun sch schemas schema x y.
187187 ( Has sch schemas schema
188− , Has fun schema ('Function ('[x] '::--> 'Returns y))
188+ , Has fun schema ('Function ('[x] :=> 'Returns y))
189189 , KnownSymbol op )
190− => Alias fun
190+ => QualifiedAlias sch fun
191191 -> TypeExpression schemas x
192192 -> Definition schemas
193193 (Alter sch (Create op ('Operator ('RightOp x y)) schema) schemas)
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+10−10
@@ -34,7 +34,7 @@ module Squeal.PostgreSQL.Expression
3434 ( -- * Expression
3535 Expression (..)
3636 , Expr
37− , (:-->)
37+ , type (-->)
3838 , FunctionDB
3939 , unsafeFunction
4040 , function
@@ -48,7 +48,7 @@ module Squeal.PostgreSQL.Expression
4848 , binaryOp
4949 , FunctionVar
5050 , unsafeFunctionVar
51− , FunctionN
51+ , type (--->)
5252 , FunctionNDB
5353 , unsafeFunctionN
5454 , functionN
@@ -159,7 +159,7 @@ type OperatorDB schemas x1 x2 y
159159-- This is a subtype of the usual Haskell function type `Prelude.->`,
160160-- indeed a subcategory as it is closed under the usual
161161-- `Prelude..` and `Prelude.id`.
162−type (:-->) x y
162+type (-->) x y
163163 = forall outer commons grp schemas params from
164164 . Expression outer commons grp schemas params from x
165165 -- ^ input
@@ -179,7 +179,7 @@ Use the `*:` operator to end your argument lists, like so.
179179>>> printSQL (unsafeFunctionN "fun" (true :* false :* localTime *: true))
180180fun(TRUE, FALSE, LOCALTIME, TRUE)
181181-}
182−type FunctionN xs y
182+type (--->) xs y
183183 = forall outer commons grp schemas params from
184184 . NP (Expression outer commons grp schemas params from) xs
185185 -- ^ inputs
@@ -327,7 +327,7 @@ binaryOp = unsafeBinaryOp $ renderSymbol @op
327327
328328-- | >>> printSQL $ unsafeLeftOp "NOT" true
329329-- (NOT TRUE)
330−unsafeLeftOp :: ByteString -> x :--> y
330+unsafeLeftOp :: ByteString -> x --> y
331331unsafeLeftOp op x = UnsafeExpression $ parenthesized $ op <+> renderSQL x
332332
333333leftOp
@@ -339,7 +339,7 @@ leftOp = unsafeLeftOp $ renderSymbol @op
339339
340340-- | >>> printSQL $ true & unsafeRightOp "IS NOT TRUE"
341341-- (TRUE IS NOT TRUE)
342−unsafeRightOp :: ByteString -> x :--> y
342+unsafeRightOp :: ByteString -> x --> y
343343unsafeRightOp op x = UnsafeExpression $ parenthesized $ renderSQL x <+> op
344344
345345rightOp
@@ -351,25 +351,25 @@ rightOp = unsafeRightOp $ renderSymbol @op
351351
352352-- | >>> printSQL $ unsafeFunction "f" true
353353-- f(TRUE)
354−unsafeFunction :: ByteString -> x :--> y
354+unsafeFunction :: ByteString -> x --> y
355355unsafeFunction fun x = UnsafeExpression $
356356 fun <> parenthesized (renderSQL x)
357357
358358function
359− :: (Has sch schemas schema, Has fun schema ('Function ('[x] '::--> 'Returns y)))
359+ :: (Has sch schemas schema, Has fun schema ('Function ('[x] :=> 'Returns y)))
360360 => QualifiedAlias sch fun
361361 -> FunctionDB schemas x y
362362function = unsafeFunction . renderSQL
363363
364364-- | >>> printSQL $ unsafeFunctionN "f" (currentTime :* localTimestamp :* false *: literal 'a')
365365-- f(CURRENT_TIME, LOCALTIMESTAMP, FALSE, E'a')
366−unsafeFunctionN :: SListI xs => ByteString -> FunctionN xs y
366+unsafeFunctionN :: SListI xs => ByteString -> xs ---> y
367367unsafeFunctionN fun xs = UnsafeExpression $
368368 fun <> parenthesized (renderCommaSeparated renderSQL xs)
369369
370370functionN
371371 :: ( Has sch schemas schema
372− , Has fun schema ('Function (xs '::--> 'Returns y))
372+ , Has fun schema ('Function (xs :=> 'Returns y))
373373 , SListI xs )
374374 => QualifiedAlias sch fun
375375 -> FunctionNDB schemas xs y
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Collection.hs+2−2
@@ -111,14 +111,14 @@ array2 xss = UnsafeExpression $ "ARRAY" <>
111111
112112-- | >>> printSQL $ cardinality (array [null_, false, true])
113113-- cardinality(ARRAY[NULL, FALSE, TRUE])
114−cardinality :: null ('PGvararray ty) :--> null 'PGint8
114+cardinality :: null ('PGvararray ty) --> null 'PGint8
115115cardinality = unsafeFunction "cardinality"
116116
117117-- | >>> printSQL $ array [null_, false, true] & index 2
118118-- (ARRAY[NULL, FALSE, TRUE])[2]
119119index
120120 :: Word64 -- ^ index
121− -> null ('PGvararray ty) :--> NullifyType ty
121+ -> null ('PGvararray ty) --> NullifyType ty
122122index n expr = UnsafeExpression $
123123 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
124124
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Comparison.hs+6−6
@@ -162,7 +162,7 @@ isNotDistinctFrom = unsafeBinaryOp "IS NOT DISTINCT FROM"
162162>>> printSQL $ true & isTrue
163163(TRUE IS TRUE)
164164-}
165−isTrue :: null0 'PGbool :--> null1 'PGbool
165+isTrue :: null0 'PGbool --> null1 'PGbool
166166isTrue = unsafeRightOp "IS TRUE"
167167
168168{- | is false or unknown
@@ -170,7 +170,7 @@ isTrue = unsafeRightOp "IS TRUE"
170170>>> printSQL $ true & isNotTrue
171171(TRUE IS NOT TRUE)
172172-}
173−isNotTrue :: null0 'PGbool :--> null1 'PGbool
173+isNotTrue :: null0 'PGbool --> null1 'PGbool
174174isNotTrue = unsafeRightOp "IS NOT TRUE"
175175
176176{- | is false
@@ -178,7 +178,7 @@ isNotTrue = unsafeRightOp "IS NOT TRUE"
178178>>> printSQL $ true & isFalse
179179(TRUE IS FALSE)
180180-}
181−isFalse :: null0 'PGbool :--> null1 'PGbool
181+isFalse :: null0 'PGbool --> null1 'PGbool
182182isFalse = unsafeRightOp "IS FALSE"
183183
184184{- | is true or unknown
@@ -186,7 +186,7 @@ isFalse = unsafeRightOp "IS FALSE"
186186>>> printSQL $ true & isNotFalse
187187(TRUE IS NOT FALSE)
188188-}
189−isNotFalse :: null0 'PGbool :--> null1 'PGbool
189+isNotFalse :: null0 'PGbool --> null1 'PGbool
190190isNotFalse = unsafeRightOp "IS NOT FALSE"
191191
192192{- | is unknown
@@ -194,7 +194,7 @@ isNotFalse = unsafeRightOp "IS NOT FALSE"
194194>>> printSQL $ true & isUnknown
195195(TRUE IS UNKNOWN)
196196-}
197−isUnknown :: null0 'PGbool :--> null1 'PGbool
197+isUnknown :: null0 'PGbool --> null1 'PGbool
198198isUnknown = unsafeRightOp "IS UNKNOWN"
199199
200200{- | is true or false
@@ -202,5 +202,5 @@ isUnknown = unsafeRightOp "IS UNKNOWN"
202202>>> printSQL $ true & isNotUnknown
203203(TRUE IS NOT UNKNOWN)
204204-}
205−isNotUnknown :: null0 'PGbool :--> null1 'PGbool
205+isNotUnknown :: null0 'PGbool --> null1 'PGbool
206206isNotUnknown = unsafeRightOp "IS NOT UNKNOWN"
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Json.hs+27−34
@@ -188,7 +188,7 @@ Table 9.45: JSON creation functions
188188-- otherwise, a scalar value is produced. For any scalar type other than a
189189-- number, a Boolean, or a null value, the text representation will be used, in
190190-- such a fashion that it is a valid json value.
191−toJson :: null ty :--> null 'PGjson
191+toJson :: null ty --> null 'PGjson
192192toJson = unsafeFunction "to_json"
193193
194194-- | Returns the value as jsonb. Arrays and composites are converted
@@ -197,26 +197,26 @@ toJson = unsafeFunction "to_json"
197197-- otherwise, a scalar value is produced. For any scalar type other than a
198198-- number, a Boolean, or a null value, the text representation will be used, in
199199-- such a fashion that it is a valid jsonb value.
200−toJsonb :: null ty :--> null 'PGjsonb
200+toJsonb :: null ty --> null 'PGjsonb
201201toJsonb = unsafeFunction "to_jsonb"
202202
203203-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
204204-- becomes a JSON array of arrays.
205−arrayToJson :: null ('PGvararray ty) :--> null 'PGjson
205+arrayToJson :: null ('PGvararray ty) --> null 'PGjson
206206arrayToJson = unsafeFunction "array_to_json"
207207
208208-- | Returns the row as a JSON object.
209−rowToJson :: null ('PGcomposite ty) :--> null 'PGjson
209+rowToJson :: null ('PGcomposite ty) --> null 'PGjson
210210rowToJson = unsafeFunction "row_to_json"
211211
212212-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
213213-- argument list.
214−jsonBuildArray :: SOP.SListI tuple => FunctionN tuple (null 'PGjson)
214+jsonBuildArray :: SOP.SListI tuple => tuple ---> null 'PGjson
215215jsonBuildArray = unsafeFunctionN "json_build_array"
216216
217217-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
218218-- variadic argument list.
219−jsonbBuildArray :: SOP.SListI tuple => FunctionN tuple (null 'PGjsonb)
219+jsonbBuildArray :: SOP.SListI tuple => tuple ---> null 'PGjsonb
220220jsonbBuildArray = unsafeFunctionN "jsonb_build_array"
221221
222222-- | Builds a possibly-heterogeneously-typed JSON object out of a variadic
@@ -224,10 +224,10 @@ jsonbBuildArray = unsafeFunctionN "jsonb_build_array"
224224-- and values.
225225class SOP.SListI tys => JsonBuildObject tys where
226226
227− jsonBuildObject :: FunctionN tys (null 'PGjson)
227+ jsonBuildObject :: tys ---> null 'PGjson
228228 jsonBuildObject = unsafeFunctionN "json_build_object"
229229
230− jsonbBuildObject :: FunctionN tys (null 'PGjsonb)
230+ jsonbBuildObject :: tys ---> null 'PGjsonb
231231 jsonbBuildObject = unsafeFunctionN "jsonb_build_object"
232232
233233instance JsonBuildObject '[]
@@ -240,7 +240,7 @@ instance (JsonBuildObject tys, key `In` PGJsonKey)
240240-- which are taken as a key/value pair.
241241jsonObject
242242 :: null ('PGfixarray '[n,2] ('NotNull 'PGtext))
243− :--> null 'PGjson
243+ --> null 'PGjson
244244jsonObject = unsafeFunction "json_object"
245245
246246-- | Builds a binary JSON object out of a text array.
@@ -249,24 +249,24 @@ jsonObject = unsafeFunction "json_object"
249249-- which are taken as a key/value pair.
250250jsonbObject
251251 :: null ('PGfixarray '[n,2] ('NotNull 'PGtext))
252− :--> null 'PGjsonb
252+ --> null 'PGjsonb
253253jsonbObject = unsafeFunction "jsonb_object"
254254
255255-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
256256-- keys and one for values, that are zipped pairwise to create a JSON object.
257−jsonZipObject :: FunctionN
257+jsonZipObject ::
258258 '[ null ('PGvararray ('NotNull 'PGtext))
259259 , null ('PGvararray ('NotNull 'PGtext)) ]
260− ( null 'PGjson )
260+ ---> null 'PGjson
261261jsonZipObject = unsafeFunctionN "json_object"
262262
263263-- | This is an alternate form of 'jsonbObject' that takes two arrays; one for
264264-- keys and one for values, that are zipped pairwise to create a binary JSON
265265-- object.
266−jsonbZipObject :: FunctionN
266+jsonbZipObject ::
267267 '[ null ('PGvararray ('NotNull 'PGtext))
268268 , null ('PGvararray ('NotNull 'PGtext)) ]
269− ( null 'PGjsonb )
269+ ---> null 'PGjsonb
270270jsonbZipObject = unsafeFunctionN "jsonb_object"
271271
272272{-----------------------------------------
@@ -274,31 +274,31 @@ Table 9.46: JSON processing functions
274274-----------------------------------------}
275275
276276-- | Returns the number of elements in the outermost JSON array.
277−jsonArrayLength :: null 'PGjson :--> null 'PGint4
277+jsonArrayLength :: null 'PGjson --> null 'PGint4
278278jsonArrayLength = unsafeFunction "json_array_length"
279279
280280-- | Returns the number of elements in the outermost binary JSON array.
281−jsonbArrayLength :: null 'PGjsonb :--> null 'PGint4
281+jsonbArrayLength :: null 'PGjsonb --> null 'PGint4
282282jsonbArrayLength = unsafeFunction "jsonb_array_length"
283283
284284-- | Returns the type of the outermost JSON value as a text string. Possible
285285-- types are object, array, string, number, boolean, and null.
286−jsonTypeof :: null 'PGjson :--> null 'PGtext
286+jsonTypeof :: null 'PGjson --> null 'PGtext
287287jsonTypeof = unsafeFunction "json_typeof"
288288
289289-- | Returns the type of the outermost binary JSON value as a text string.
290290-- Possible types are object, array, string, number, boolean, and null.
291−jsonbTypeof :: null 'PGjsonb :--> null 'PGtext
291+jsonbTypeof :: null 'PGjsonb --> null 'PGtext
292292jsonbTypeof = unsafeFunction "jsonb_typeof"
293293
294294-- | Returns its argument with all object fields that have null values omitted.
295295-- Other null values are untouched.
296−jsonStripNulls :: null 'PGjson :--> null 'PGjson
296+jsonStripNulls :: null 'PGjson --> null 'PGjson
297297jsonStripNulls = unsafeFunction "json_strip_nulls"
298298
299299-- | Returns its argument with all object fields that have null values omitted.
300300-- Other null values are untouched.
301−jsonbStripNulls :: null 'PGjsonb :--> null 'PGjsonb
301+jsonbStripNulls :: null 'PGjsonb --> null 'PGjsonb
302302jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
303303
304304-- | @ jsonbSet target path new_value create_missing @
@@ -309,12 +309,9 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
309309-- item designated by path does not exist. As with the path orientated
310310-- operators, negative integers that appear in path count from the end of JSON
311311-- arrays.
312−jsonbSet
313− :: FunctionN
314− '[ null 'PGjsonb
315− , null ('PGvararray ('NotNull 'PGtext))
316− , null 'PGjsonb
317− , null 'PGbool ] (null 'PGjsonb)
312+jsonbSet ::
313+ '[ null 'PGjsonb, null ('PGvararray ('NotNull 'PGtext))
314+ , null 'PGjsonb, null 'PGbool ] ---> null 'PGjsonb
318315jsonbSet = unsafeFunctionN "jsonbSet"
319316
320317-- | @ jsonbInsert target path new_value insert_after @
@@ -326,19 +323,15 @@ jsonbSet = unsafeFunctionN "jsonbSet"
326323-- path is in JSONB object, @new_value@ will be inserted only if target does not
327324-- exist. As with the path orientated operators, negative integers that appear
328325-- in path count from the end of JSON arrays.
329−jsonbInsert
330− :: FunctionN
331− '[ null 'PGjsonb
332− , null ('PGvararray ('NotNull 'PGtext))
333− , null 'PGjsonb
334− , null 'PGbool ] (null 'PGjsonb)
326+jsonbInsert ::
327+ '[ null 'PGjsonb, null ('PGvararray ('NotNull 'PGtext))
328+ , null 'PGjsonb, null 'PGbool ] ---> null 'PGjsonb
335329jsonbInsert = unsafeFunctionN "jsonb_insert"
336330
337331-- | Returns its argument as indented JSON text.
338−jsonbPretty :: null 'PGjsonb :--> null 'PGtext
332+jsonbPretty :: null 'PGjsonb --> null 'PGtext
339333jsonbPretty = unsafeFunction "jsonb_pretty"
340334
341−
342335{- | Expands the outermost JSON object into a set of key/value pairs.
343336
344337>>> printSQL (select Star (from (jsonEach (literal (Json (object ["a" .= "foo", "b" .= "bar"]))))))
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Logic.hs+1−1
@@ -47,7 +47,7 @@ false = UnsafeExpression "FALSE"
4747
4848-- | >>> printSQL $ not_ true
4949-- (NOT TRUE)
50−not_ :: null 'PGbool :--> null 'PGbool
50+not_ :: null 'PGbool --> null 'PGbool
5151not_ = unsafeLeftOp "NOT"
5252
5353-- | >>> printSQL $ true .&& false
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Math.hs+4−6
@@ -37,9 +37,7 @@ import Squeal.PostgreSQL.Schema
3737-- in printSQL expression
3838-- :}
3939-- atan2(pi(), 2)
40−atan2_
41− :: float `In` PGFloating
42− => FunctionN '[ null float, null float] (null float)
40+atan2_ :: float `In` PGFloating => '[ null float, null float] ---> null float
4341atan2_ = unsafeFunctionN "atan2"
4442
4543
@@ -78,7 +76,7 @@ rem_ = unsafeBinaryOp "%"
7876-- in printSQL expression
7977-- :}
8078-- trunc(pi())
81−trunc :: frac `In` PGFloating => null frac :--> null frac
79+trunc :: frac `In` PGFloating => null frac --> null frac
8280trunc = unsafeFunction "trunc"
8381
8482-- | >>> :{
@@ -88,7 +86,7 @@ trunc = unsafeFunction "trunc"
8886-- in printSQL expression
8987-- :}
9088-- round(pi())
91−round_ :: frac `In` PGFloating => null frac :--> null frac
89+round_ :: frac `In` PGFloating => null frac --> null frac
9290round_ = unsafeFunction "round"
9391
9492-- | >>> :{
@@ -98,5 +96,5 @@ round_ = unsafeFunction "round"
9896-- in printSQL expression
9997-- :}
10098-- ceiling(pi())
101−ceiling_ :: frac `In` PGFloating => null frac :--> null frac
99+ceiling_ :: frac `In` PGFloating => null frac --> null frac
102100ceiling_ = unsafeFunction "ceiling"
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Null.hs+4−4
@@ -44,7 +44,7 @@ null_ = UnsafeExpression "NULL"
4444--
4545-- >>> printSQL $ notNull true
4646-- TRUE
47−notNull :: 'NotNull ty :--> 'Null ty
47+notNull :: 'NotNull ty --> 'Null ty
4848notNull = UnsafeExpression . renderSQL
4949
5050-- | return the leftmost value which is not NULL
@@ -69,12 +69,12 @@ fromNull notNullx nullx = coalesce [nullx] notNullx
6969
7070-- | >>> printSQL $ null_ & isNull
7171-- NULL IS NULL
72−isNull :: 'Null ty :--> null 'PGbool
72+isNull :: 'Null ty --> null 'PGbool
7373isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
7474
7575-- | >>> printSQL $ null_ & isNotNull
7676-- NULL IS NOT NULL
77−isNotNull :: 'Null ty :--> null 'PGbool
77+isNotNull :: 'Null ty --> null 'PGbool
7878isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
7979
8080-- | analagous to `maybe` using @IS NULL@
@@ -100,5 +100,5 @@ matchNull y f x = ifThenElse (isNull x) y
100100>>> printSQL expr
101101NULLIF(FALSE, ($1 :: bool))
102102-}
103−nullIf :: FunctionN '[ 'NotNull ty, 'NotNull ty] ('Null ty)
103+nullIf :: '[ 'NotNull ty, 'NotNull ty] ---> 'Null ty
104104nullIf = unsafeFunctionN "NULLIF"
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Range.hs+8−9
@@ -205,27 +205,26 @@ whole = NonEmpty Infinite Infinite
205205(@-) :: Operator (null ('PGrange ty)) (null ('PGrange ty)) (null ('PGrange ty))
206206(@-) = unsafeBinaryOp "-"
207207
208−lowerBound :: null ('PGrange ty) :--> 'Null ty
208+lowerBound :: null ('PGrange ty) --> 'Null ty
209209lowerBound = unsafeFunction "lower"
210210
211−upperBound :: null ('PGrange ty) :--> 'Null ty
211+upperBound :: null ('PGrange ty) --> 'Null ty
212212upperBound = unsafeFunction "upper"
213213
214−isEmpty :: null ('PGrange ty) :--> 'Null 'PGbool
214+isEmpty :: null ('PGrange ty) --> 'Null 'PGbool
215215isEmpty = unsafeFunction "isempty"
216216
217−lowerInc :: null ('PGrange ty) :--> 'Null 'PGbool
217+lowerInc :: null ('PGrange ty) --> 'Null 'PGbool
218218lowerInc = unsafeFunction "lower_inc"
219219
220−lowerInf :: null ('PGrange ty) :--> 'Null 'PGbool
220+lowerInf :: null ('PGrange ty) --> 'Null 'PGbool
221221lowerInf = unsafeFunction "lower_inf"
222222
223−upperInc :: null ('PGrange ty) :--> 'Null 'PGbool
223+upperInc :: null ('PGrange ty) --> 'Null 'PGbool
224224upperInc = unsafeFunction "upper_inc"
225225
226−upperInf :: null ('PGrange ty) :--> 'Null 'PGbool
226+upperInf :: null ('PGrange ty) --> 'Null 'PGbool
227227upperInf = unsafeFunction "upper_inf"
228228
229−rangeMerge :: FunctionN
230− '[ null ('PGrange ty), null ('PGrange ty)] (null ('PGrange ty))
229+rangeMerge :: '[null ('PGrange ty), null ('PGrange ty)] ---> null ('PGrange ty)
231230rangeMerge = unsafeFunctionN "range_merge"
squeal-postgresql/src/Squeal/PostgreSQL/Expression/SetOf.hs+22−10
@@ -26,9 +26,11 @@ module Squeal.PostgreSQL.Expression.SetOf
2626 , generateSeriesTimestamp
2727 , SetOfFunction
2828 , unsafeSetOfFunction
29+ , SetOfFunctionDB
2930 , setOfFunction
3031 , SetOfFunctionN
3132 , unsafeSetOfFunctionN
33+ , SetOfFunctionNDB
3234 , setOfFunctionN
3335 ) where
3436
@@ -53,6 +55,13 @@ type SetOfFunction fun ty setof
5355 -> FromClause outer commons schemas params '[fun ::: setof]
5456 -- ^ output
5557
58+type SetOfFunctionDB fun schemas ty setof
59+ = forall outer commons params
60+ . Expression outer commons 'Ungrouped schemas params '[] ty
61+ -- ^ input
62+ -> FromClause outer commons schemas params '[fun ::: setof]
63+ -- ^ output
64+
5665-- | Escape hatch for a set returning function with 1 argument.
5766unsafeSetOfFunction
5867 :: forall fun ty setof. KnownSymbol fun
@@ -62,11 +71,9 @@ unsafeSetOfFunction x = UnsafeFromClause $
6271
6372setOfFunction
6473 :: ( Has sch schemas schema
65− , Has fun schema ('Function ('[ty] '::--> 'ReturnsTable setof)) )
66− => Alias fun
67− -> ( forall outer commons params
68− . Expression outer commons 'Ungrouped schemas params '[] ty
69− -> FromClause outer commons schemas params '[fun ::: setof] )
74+ , Has fun schema ('Function ('[ty] :=> 'ReturnsTable setof)) )
75+ => QualifiedAlias sch fun
76+ -> SetOfFunctionDB fun schemas ty setof
7077setOfFunction _ = unsafeSetOfFunction
7178
7279{- |
@@ -86,14 +93,19 @@ unsafeSetOfFunctionN
8693unsafeSetOfFunctionN xs = UnsafeFromClause $
8794 renderSymbol @fun <> parenthesized (renderCommaSeparated renderSQL xs)
8895
96+type SetOfFunctionNDB fun schemas tys setof
97+ = forall outer commons params
98+ . NP (Expression outer commons 'Ungrouped schemas params '[]) tys
99+ -- ^ inputs
100+ -> FromClause outer commons schemas params '[fun ::: setof]
101+ -- ^ output
102+
89103setOfFunctionN
90104 :: ( Has sch schemas schema
91− , Has fun schema ('Function (tys '::--> 'ReturnsTable setof))
105+ , Has fun schema ('Function (tys :=> 'ReturnsTable setof))
92106 , SOP.SListI tys )
93− => Alias fun
94− -> ( forall outer commons params
95− . NP (Expression outer commons 'Ungrouped schemas params '[]) tys
96− -> FromClause outer commons schemas params '[fun ::: setof] )
107+ => QualifiedAlias sch fun
108+ -> SetOfFunctionNDB fun schemas tys setof
97109setOfFunctionN _ = unsafeSetOfFunctionN
98110
99111{- | @generateSeries (start *: stop)@
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Text.hs+3−3
@@ -30,17 +30,17 @@ import Squeal.PostgreSQL.Schema
3030
3131-- | >>> printSQL $ lower "ARRRGGG"
3232-- lower(E'ARRRGGG')
33−lower :: null 'PGtext :--> null 'PGtext
33+lower :: null 'PGtext --> null 'PGtext
3434lower = unsafeFunction "lower"
3535
3636-- | >>> printSQL $ upper "eeee"
3737-- upper(E'eeee')
38−upper :: null 'PGtext :--> null 'PGtext
38+upper :: null 'PGtext --> null 'PGtext
3939upper = unsafeFunction "upper"
4040
4141-- | >>> printSQL $ charLength "four"
4242-- char_length(E'four')
43−charLength :: null 'PGtext :--> null 'PGint4
43+charLength :: null 'PGtext --> null 'PGint4
4444charLength = unsafeFunction "char_length"
4545
4646-- | The `like` expression returns true if the @string@ matches
squeal-postgresql/src/Squeal/PostgreSQL/Expression/TextSearch.hs+19−20
@@ -55,7 +55,7 @@ import Squeal.PostgreSQL.Schema
5555(.|) = unsafeBinaryOp "||"
5656
5757-- | negate a `Squeal.PostgreSQL.Expression.Type.tsquery`
58−(.!) :: null 'PGtsquery :--> null 'PGtsquery
58+(.!) :: null 'PGtsquery --> null 'PGtsquery
5959(.!) = unsafeLeftOp "!!"
6060
6161-- | `Squeal.PostgreSQL.Expression.Type.tsquery` followed by
@@ -66,51 +66,50 @@ import Squeal.PostgreSQL.Schema
6666-- | convert array of lexemes to `Squeal.PostgreSQL.Expression.Type.tsvector`
6767arrayToTSvector
6868 :: null ('PGvararray ('NotNull 'PGtext))
69− :--> null 'PGtsvector
69+ --> null 'PGtsvector
7070arrayToTSvector = unsafeFunction "array_to_tsvector"
7171
7272-- | number of lexemes in `Squeal.PostgreSQL.Expression.Type.tsvector`
73−tsvectorLength :: null 'PGtsvector :--> null 'PGint4
73+tsvectorLength :: null 'PGtsvector --> null 'PGint4
7474tsvectorLength = unsafeFunction "length"
7575
7676-- | number of lexemes plus operators in `Squeal.PostgreSQL.Expression.Type.tsquery`
77−numnode :: null 'PGtsquery :--> null 'PGint4
77+numnode :: null 'PGtsquery --> null 'PGint4
7878numnode = unsafeFunction "numnode"
7979
8080-- | produce `Squeal.PostgreSQL.Expression.Type.tsquery` ignoring punctuation
81−plainToTSquery :: null 'PGtext :--> null 'PGtsquery
81+plainToTSquery :: null 'PGtext --> null 'PGtsquery
8282plainToTSquery = unsafeFunction "plainto_tsquery"
8383
8484-- | produce `Squeal.PostgreSQL.Expression.Type.tsquery` that searches for a phrase,
8585-- ignoring punctuation
86−phraseToTSquery :: null 'PGtext :--> null 'PGtsquery
86+phraseToTSquery :: null 'PGtext --> null 'PGtsquery
8787phraseToTSquery = unsafeFunction "phraseto_tsquery"
8888
8989-- | produce `Squeal.PostgreSQL.Expression.Type.tsquery` from a web search style query
90−websearchToTSquery :: null 'PGtext :--> null 'PGtsquery
90+websearchToTSquery :: null 'PGtext --> null 'PGtsquery
9191websearchToTSquery = unsafeFunction "websearch_to_tsquery"
9292
9393-- | get indexable part of a `Squeal.PostgreSQL.Expression.Type.tsquery`
94−queryTree :: null 'PGtsquery :--> null 'PGtext
94+queryTree :: null 'PGtsquery --> null 'PGtext
9595queryTree = unsafeFunction "query_tree"
9696
9797-- | normalize words and convert to `Squeal.PostgreSQL.Expression.Type.tsquery`
98−toTSquery :: null 'PGtext :--> null 'PGtsquery
98+toTSquery :: null 'PGtext --> null 'PGtsquery
9999toTSquery = unsafeFunction "to_tsquery"
100100
101101-- | reduce document text to `Squeal.PostgreSQL.Expression.Type.tsvector`
102102toTSvector
103103 :: ty `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
104− => null ty :--> null 'PGtsvector
104+ => null ty --> null 'PGtsvector
105105toTSvector = unsafeFunction "to_tsvector"
106106
107107-- | assign weight to each element of `Squeal.PostgreSQL.Expression.Type.tsvector`
108−setWeight
109− :: FunctionN '[null 'PGtsvector, null ('PGchar 1)] (null 'PGtsvector)
108+setWeight :: '[null 'PGtsvector, null ('PGchar 1)] ---> null 'PGtsvector
110109setWeight = unsafeFunctionN "set_weight"
111110
112111-- | remove positions and weights from `Squeal.PostgreSQL.Expression.Type.tsvector`
113−strip :: null 'PGtsvector :--> null 'PGtsvector
112+strip :: null 'PGtsvector --> null 'PGtsvector
114113strip = unsafeFunction "strip"
115114
116115-- | @jsonToTSvector (document *: filter)@
@@ -123,7 +122,7 @@ strip = unsafeFunction "strip"
123122-- "boolean" (to include all Boolean values in the string format "true"/"false"),
124123-- "key" (to include all keys) or "all" (to include all above).
125124-- These values can be combined together to include, e.g. all string and numeric values.
126−jsonToTSvector :: FunctionN '[null 'PGjson, null 'PGjson] (null 'PGtsvector)
125+jsonToTSvector :: '[null 'PGjson, null 'PGjson] ---> null 'PGtsvector
127126jsonToTSvector = unsafeFunctionN "json_to_tsvector"
128127
129128-- | @jsonbToTSvector (document *: filter)@
@@ -136,23 +135,23 @@ jsonToTSvector = unsafeFunctionN "json_to_tsvector"
136135-- "boolean" (to include all Boolean values in the string format "true"/"false"),
137136-- "key" (to include all keys) or "all" (to include all above).
138137-- These values can be combined together to include, e.g. all string and numeric values.
139−jsonbToTSvector :: FunctionN '[null 'PGjsonb, null 'PGjsonb] (null 'PGtsvector)
138+jsonbToTSvector :: '[null 'PGjsonb, null 'PGjsonb] ---> null 'PGtsvector
140139jsonbToTSvector = unsafeFunctionN "jsonb_to_tsvector"
141140
142141-- | remove given lexeme from `Squeal.PostgreSQL.Expression.Type.tsvector`
143−tsDelete :: FunctionN
142+tsDelete ::
144143 '[null 'PGtsvector, null ('PGvararray ('NotNull 'PGtext))]
145− (null 'PGtsvector)
144+ ---> null 'PGtsvector
146145tsDelete = unsafeFunctionN "ts_delete"
147146
148147-- | select only elements with given weights from `Squeal.PostgreSQL.Expression.Type.tsvector`
149−tsFilter :: FunctionN
148+tsFilter ::
150149 '[null 'PGtsvector, null ('PGvararray ('NotNull ('PGchar 1)))]
151− (null 'PGtsvector)
150+ ---> null 'PGtsvector
152151tsFilter = unsafeFunctionN "ts_filter"
153152
154153-- | display a `Squeal.PostgreSQL.Expression.Type.tsquery` match
155154tsHeadline
156155 :: document `In` '[ 'PGtext, 'PGjson, 'PGjsonb]
157− => FunctionN '[null document, null 'PGtsquery] (null 'PGtext)
156+ => '[null document, null 'PGtsquery] ---> null 'PGtext
158157tsHeadline = unsafeFunctionN "ts_headline"
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Time.hs+7−12
@@ -17,6 +17,7 @@ Date/Time functions and operators
1717 , OverloadedStrings
1818 , PolyKinds
1919 , RankNTypes
20+ , TypeOperators
2021#-}
2122
2223module Squeal.PostgreSQL.Expression.Time
@@ -85,9 +86,7 @@ Create date from year, month and day fields
8586>>> printSQL (makeDate (1984 :* 7 *: 3))
8687make_date(1984, 7, 3)
8788-}
88−makeDate :: FunctionN
89− '[ null 'PGint4, null 'PGint4, null 'PGint4 ]
90− ( null 'PGdate )
89+makeDate :: '[ null 'PGint4, null 'PGint4, null 'PGint4 ] ---> null 'PGdate
9190makeDate = unsafeFunctionN "make_date"
9291
9392{-|
@@ -96,9 +95,7 @@ Create time from hour, minute and seconds fields
9695>>> printSQL (makeTime (8 :* 15 *: 23.5))
9796make_time(8, 15, 23.5)
9897-}
99−makeTime :: FunctionN
100− '[ null 'PGint4, null 'PGint4, null 'PGfloat8 ]
101− ( null 'PGtime )
98+makeTime :: '[ null 'PGint4, null 'PGint4, null 'PGfloat8 ] ---> null 'PGtime
10299makeTime = unsafeFunctionN "make_time"
103100
104101{-|
@@ -107,10 +104,9 @@ Create timestamp from year, month, day, hour, minute and seconds fields
107104>>> printSQL (makeTimestamp (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
108105make_timestamp(2013, 7, 15, 8, 15, 23.5)
109106-}
110−makeTimestamp :: FunctionN
107+makeTimestamp ::
111108 '[ null 'PGint4, null 'PGint4, null 'PGint4
112− , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
113− ( null 'PGtimestamp )
109+ , null 'PGint4, null 'PGint4, null 'PGfloat8 ] ---> null 'PGtimestamp
114110makeTimestamp = unsafeFunctionN "make_timestamp"
115111
116112{-|
@@ -121,10 +117,9 @@ the current time zone is used
121117>>> printSQL (makeTimestamptz (2013 :* 7 :* 15 :* 8 :* 15 *: 23.5))
122118make_timestamptz(2013, 7, 15, 8, 15, 23.5)
123119-}
124−makeTimestamptz :: FunctionN
120+makeTimestamptz ::
125121 '[ null 'PGint4, null 'PGint4, null 'PGint4
126− , null 'PGint4, null 'PGint4, null 'PGfloat8 ]
127− ( null 'PGtimestamptz )
122+ , null 'PGint4, null 'PGint4, null 'PGfloat8 ] ---> null 'PGtimestamptz
128123makeTimestamptz = unsafeFunctionN "make_timestamptz"
129124
130125{-|
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−2
@@ -45,7 +45,7 @@ module Squeal.PostgreSQL.Schema
4545 , TableType
4646 , SchemumType (..)
4747 , IndexType (..)
48− , FunctionType (..)
48+ , FunctionType
4949 , OperatorType (..)
5050 , ReturnsType (..)
5151 , SchemaType
@@ -433,7 +433,7 @@ data SchemumType
433433 | Operator OperatorType
434434 | UnsafeSchemum Symbol
435435
436−data FunctionType = (::-->) [NullityType] ReturnsType
436+type FunctionType = ([NullityType], ReturnsType)
437437
438438data IndexType
439439 = Btree