on dev help sign in
SetOf ~> Set
commit5cc04695d52f3ba9fd6b840183e4719b5c23754c authorEitan Chatav <eitan@EEM109LMBP-1.local> dateWed 25 Sep 2019, 15:37 (7 years ago) parentb40c66b
5 files changed+54−54
squeal-postgresql/squeal-postgresql.cabal+1−1 squeal-postgresql/src/Squeal/PostgreSQL.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Collection.hs+3−3 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Json.hs+13−13 squeal-postgresql/src/Squeal/PostgreSQL/Expression/SetOf.hs → squeal-postgresql/src/Squeal/PostgreSQL/Expression/Set.hs+36−36
squeal-postgresql/squeal-postgresql.cabal+1−1
@@ -44,7 +44,7 @@ library
4444 Squeal.PostgreSQL.Expression.Null
4545 Squeal.PostgreSQL.Expression.Parameter
4646 Squeal.PostgreSQL.Expression.Range
47− Squeal.PostgreSQL.Expression.SetOf
47+ Squeal.PostgreSQL.Expression.Set
4848 Squeal.PostgreSQL.Expression.Sort
4949 Squeal.PostgreSQL.Expression.Subquery
5050 Squeal.PostgreSQL.Expression.Text
squeal-postgresql/src/Squeal/PostgreSQL.hs+1−1
@@ -214,7 +214,7 @@ import Squeal.PostgreSQL.Expression.Math as X
214214import Squeal.PostgreSQL.Expression.Null as X
215215import Squeal.PostgreSQL.Expression.Parameter as X
216216import Squeal.PostgreSQL.Expression.Range as X
217−import Squeal.PostgreSQL.Expression.SetOf as X
217+import Squeal.PostgreSQL.Expression.Set as X
218218import Squeal.PostgreSQL.Expression.Sort as X
219219import Squeal.PostgreSQL.Expression.Subquery as X
220220import Squeal.PostgreSQL.Expression.Text as X
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Collection.hs+3−3
@@ -42,7 +42,7 @@ import qualified Generics.SOP as SOP
4242
4343import Squeal.PostgreSQL.Alias
4444import Squeal.PostgreSQL.Expression
45−import Squeal.PostgreSQL.Expression.SetOf
45+import Squeal.PostgreSQL.Expression.Set
4646import Squeal.PostgreSQL.List
4747import Squeal.PostgreSQL.Render
4848import Squeal.PostgreSQL.Schema
@@ -123,8 +123,8 @@ index n expr = UnsafeExpression $
123123 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
124124
125125-- | Expand an array to a set of rows
126−unnest :: SetOfFunction "unnest" (null ('PGvararray ty)) '["unnest" ::: ty]
127−unnest = unsafeSetOfFunction
126+unnest :: SetFunction "unnest" (null ('PGvararray ty)) '["unnest" ::: ty]
127+unnest = unsafeSetFunction
128128
129129-- | A row constructor is an expression that builds a row value
130130-- (also called a composite value) using values for its member fields.
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Json.hs+13−13
@@ -81,7 +81,7 @@ import GHC.TypeLits
8181
8282import Squeal.PostgreSQL.Alias
8383import Squeal.PostgreSQL.Expression
84−import Squeal.PostgreSQL.Expression.SetOf
84+import Squeal.PostgreSQL.Expression.Set
8585import Squeal.PostgreSQL.Expression.Type
8686import Squeal.PostgreSQL.List
8787import Squeal.PostgreSQL.Query
@@ -337,9 +337,9 @@ jsonbPretty = unsafeFunction "jsonb_pretty"
337337>>> printSQL (select Star (from (jsonEach (literal (Json (object ["a" .= "foo", "b" .= "bar"]))))))
338338SELECT * FROM json_each(('{"a":"foo","b":"bar"}' :: json))
339339-}
340−jsonEach :: SetOfFunction "json_each" (null 'PGjson)
340+jsonEach :: SetFunction "json_each" (null 'PGjson)
341341 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
342−jsonEach = unsafeSetOfFunction
342+jsonEach = unsafeSetFunction
343343
344344{- | Expands the outermost binary JSON object into a set of key/value pairs.
345345
@@ -347,9 +347,9 @@ jsonEach = unsafeSetOfFunction
347347SELECT * FROM jsonb_each(('{"a":"foo","b":"bar"}' :: jsonb))
348348-}
349349jsonbEach
350− :: SetOfFunction "jsonb_each" (nullity 'PGjsonb)
350+ :: SetFunction "jsonb_each" (nullity 'PGjsonb)
351351 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
352−jsonbEach = unsafeSetOfFunction
352+jsonbEach = unsafeSetFunction
353353
354354{- | Expands the outermost JSON object into a set of key/value pairs.
355355
@@ -357,9 +357,9 @@ jsonbEach = unsafeSetOfFunction
357357SELECT * FROM json_each_text(('{"a":"foo","b":"bar"}' :: json))
358358-}
359359jsonEachText
360− :: SetOfFunction "json_each_text" (null 'PGjson)
360+ :: SetFunction "json_each_text" (null 'PGjson)
361361 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
362−jsonEachText = unsafeSetOfFunction
362+jsonEachText = unsafeSetFunction
363363
364364{- | Expands the outermost binary JSON object into a set of key/value pairs.
365365
@@ -367,9 +367,9 @@ jsonEachText = unsafeSetOfFunction
367367SELECT * FROM jsonb_each_text(('{"a":"foo","b":"bar"}' :: jsonb))
368368-}
369369jsonbEachText
370− :: SetOfFunction "jsonb_each_text" (null 'PGjsonb)
370+ :: SetFunction "jsonb_each_text" (null 'PGjsonb)
371371 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
372−jsonbEachText = unsafeSetOfFunction
372+jsonbEachText = unsafeSetFunction
373373
374374{- | Returns set of keys in the outermost JSON object.
375375
@@ -377,9 +377,9 @@ jsonbEachText = unsafeSetOfFunction
377377json_object_keys(('{"a":"foo","b":"bar"}' :: json))
378378-}
379379jsonObjectKeys
380− :: SetOfFunction "json_object_keys" (nullity 'PGjson)
380+ :: SetFunction "json_object_keys" (nullity 'PGjson)
381381 '["json_object_keys" ::: 'NotNull 'PGtext]
382−jsonObjectKeys = unsafeSetOfFunction
382+jsonObjectKeys = unsafeSetFunction
383383
384384{- | Returns set of keys in the outermost JSON object.
385385
@@ -387,9 +387,9 @@ jsonObjectKeys = unsafeSetOfFunction
387387jsonb_object_keys(('{"a":"foo","b":"bar"}' :: jsonb))
388388-}
389389jsonbObjectKeys
390− :: SetOfFunction "jsonb_object_keys" (null 'PGjsonb)
390+ :: SetFunction "jsonb_object_keys" (null 'PGjsonb)
391391 '["jsonb_object_keys" ::: 'NotNull 'PGtext]
392−jsonbObjectKeys = unsafeSetOfFunction
392+jsonbObjectKeys = unsafeSetFunction
393393
394394-- | Build rows from Json types.
395395type JsonPopulateFunction fun json
squeal-postgresql/src/Squeal/PostgreSQL/Expression/SetOf.hs → squeal-postgresql/src/Squeal/PostgreSQL/Expression/Set.hsrenamed+36−36
@@ -1,5 +1,5 @@
11{-|
2−Module: Squeal.PostgreSQL.Expression.SetOf
2+Module: Squeal.PostgreSQL.Expression.Set
33Description: Set returning functions
44Copyright: (c) Eitan Chatav, 2019
55Maintainer: eitan@morphism.tech
@@ -20,17 +20,17 @@ Set returning functions
2020 , TypeOperators
2121#-}
2222
23−module Squeal.PostgreSQL.Expression.SetOf
23+module Squeal.PostgreSQL.Expression.Set
2424 ( generateSeries
2525 , generateSeriesStep
2626 , generateSeriesTimestamp
27− , SetOfFunction
28− , unsafeSetOfFunction
29− , SetOfFunctionDB
27+ , SetFunction
28+ , unsafeSetFunction
29+ , SetFunctionDB
3030 , setOfFunction
31− , SetOfFunctionN
32− , unsafeSetOfFunctionN
33− , SetOfFunctionNDB
31+ , SetFunctionN
32+ , unsafeSetFunctionN
33+ , SetFunctionNDB
3434 , setOfFunctionN
3535 ) where
3636
@@ -48,65 +48,65 @@ import Squeal.PostgreSQL.Schema
4848{- |
4949A @RankNType@ for set returning functions with 1 argument.
5050-}
51−type SetOfFunction fun ty setof
51+type SetFunction fun ty row
5252 = forall outer commons schemas params
5353 . Expression outer commons 'Ungrouped schemas params '[] ty
5454 -- ^ input
55− -> FromClause outer commons schemas params '[fun ::: setof]
55+ -> FromClause outer commons schemas params '[fun ::: row]
5656 -- ^ output
5757
58−type SetOfFunctionDB fun schemas ty setof
58+type SetFunctionDB fun schemas ty row
5959 = forall outer commons params
6060 . Expression outer commons 'Ungrouped schemas params '[] ty
6161 -- ^ input
62− -> FromClause outer commons schemas params '[fun ::: setof]
62+ -> FromClause outer commons schemas params '[fun ::: row]
6363 -- ^ output
6464
6565-- | Escape hatch for a set returning function with 1 argument.
66−unsafeSetOfFunction
67− :: forall fun ty setof. KnownSymbol fun
68− => SetOfFunction fun ty setof -- ^ set returning function
69−unsafeSetOfFunction x = UnsafeFromClause $
66+unsafeSetFunction
67+ :: forall fun ty row. KnownSymbol fun
68+ => SetFunction fun ty row -- ^ set returning function
69+unsafeSetFunction x = UnsafeFromClause $
7070 renderSymbol @fun <> parenthesized (renderSQL x)
7171
7272setOfFunction
7373 :: ( Has sch schemas schema
74− , Has fun schema ('Function ('[ty] :=> 'ReturnsTable setof)) )
74+ , Has fun schema ('Function ('[ty] :=> 'ReturnsTable row)) )
7575 => QualifiedAlias sch fun
76− -> SetOfFunctionDB fun schemas ty setof
77−setOfFunction _ = unsafeSetOfFunction
76+ -> SetFunctionDB fun schemas ty row
77+setOfFunction _ = unsafeSetFunction
7878
7979{- |
8080A @RankNType@ for set returning functions with multiple argument.
8181-}
82−type SetOfFunctionN fun tys setof
82+type SetFunctionN fun tys row
8383 = forall outer commons schemas params
8484 . NP (Expression outer commons 'Ungrouped schemas params '[]) tys
8585 -- ^ inputs
86− -> FromClause outer commons schemas params '[fun ::: setof]
86+ -> FromClause outer commons schemas params '[fun ::: row]
8787 -- ^ output
8888
8989-- | Escape hatch for a set returning function with multiple argument.
90−unsafeSetOfFunctionN
91− :: forall fun tys setof. (SOP.SListI tys, KnownSymbol fun)
92− => SetOfFunctionN fun tys setof -- ^ set returning function
93−unsafeSetOfFunctionN xs = UnsafeFromClause $
90+unsafeSetFunctionN
91+ :: forall fun tys row. (SOP.SListI tys, KnownSymbol fun)
92+ => SetFunctionN fun tys row -- ^ set returning function
93+unsafeSetFunctionN xs = UnsafeFromClause $
9494 renderSymbol @fun <> parenthesized (renderCommaSeparated renderSQL xs)
9595
96−type SetOfFunctionNDB fun schemas tys setof
96+type SetFunctionNDB fun schemas tys row
9797 = forall outer commons params
9898 . NP (Expression outer commons 'Ungrouped schemas params '[]) tys
9999 -- ^ inputs
100− -> FromClause outer commons schemas params '[fun ::: setof]
100+ -> FromClause outer commons schemas params '[fun ::: row]
101101 -- ^ output
102102
103103setOfFunctionN
104104 :: ( Has sch schemas schema
105− , Has fun schema ('Function (tys :=> 'ReturnsTable setof))
105+ , Has fun schema ('Function (tys :=> 'ReturnsTable row))
106106 , SOP.SListI tys )
107107 => QualifiedAlias sch fun
108− -> SetOfFunctionNDB fun schemas tys setof
109−setOfFunctionN _ = unsafeSetOfFunctionN
108+ -> SetFunctionNDB fun schemas tys row
109+setOfFunctionN _ = unsafeSetFunctionN
110110
111111{- | @generateSeries (start *: stop)@
112112
@@ -114,9 +114,9 @@ Generate a series of values, from @start@ to @stop@ with a step size of one
114114-}
115115generateSeries
116116 :: ty `In` '[ 'PGint4, 'PGint8, 'PGnumeric]
117− => SetOfFunctionN "generate_series" '[ null ty, null ty]
117+ => SetFunctionN "generate_series" '[ null ty, null ty]
118118 '["generate_series" ::: null ty] -- ^ set returning function
119−generateSeries = unsafeSetOfFunctionN
119+generateSeries = unsafeSetFunctionN
120120
121121{- | @generateSeries (start :* stop *: step)@
122122
@@ -124,9 +124,9 @@ Generate a series of values, from @start@ to @stop@ with a step size of @step@
124124-}
125125generateSeriesStep
126126 :: ty `In` '[ 'PGint4, 'PGint8, 'PGnumeric]
127− => SetOfFunctionN "generate_series" '[null ty, null ty, null ty]
127+ => SetFunctionN "generate_series" '[null ty, null ty, null ty]
128128 '["generate_series" ::: null ty] -- ^ set returning function
129−generateSeriesStep = unsafeSetOfFunctionN
129+generateSeriesStep = unsafeSetFunctionN
130130
131131{- | @generateSeries (start :* stop *: step)@
132132
@@ -134,6 +134,6 @@ Generate a series of values, from @start@ to @stop@ with a step size of @step@
134134-}
135135generateSeriesTimestamp
136136 :: ty `In` '[ 'PGtimestamp, 'PGtimestamptz]
137− => SetOfFunctionN "generate_series" '[null ty, null ty, null 'PGinterval]
137+ => SetFunctionN "generate_series" '[null ty, null ty, null 'PGinterval]
138138 '["generate_series" ::: null ty] -- ^ set returning function
139−generateSeriesTimestamp = unsafeSetOfFunctionN
139+generateSeriesTimestamp = unsafeSetFunctionN