on dev help sign in
SetOf ~> Set
5cc0469Eitan Chatav
squeal-postgresql/squeal-postgresql.cabal+1−1
@@ -44,7 +44,7 @@ library
44 Squeal.PostgreSQL.Expression.Null
44 Squeal.PostgreSQL.Expression.Null
45 Squeal.PostgreSQL.Expression.Parameter
45 Squeal.PostgreSQL.Expression.Parameter
46 Squeal.PostgreSQL.Expression.Range
46 Squeal.PostgreSQL.Expression.Range
47− Squeal.PostgreSQL.Expression.SetOf
47+ Squeal.PostgreSQL.Expression.Set
48 Squeal.PostgreSQL.Expression.Sort
48 Squeal.PostgreSQL.Expression.Sort
49 Squeal.PostgreSQL.Expression.Subquery
49 Squeal.PostgreSQL.Expression.Subquery
50 Squeal.PostgreSQL.Expression.Text
50 Squeal.PostgreSQL.Expression.Text
squeal-postgresql/src/Squeal/PostgreSQL.hs+1−1
@@ -214,7 +214,7 @@ import Squeal.PostgreSQL.Expression.Math as X
214import Squeal.PostgreSQL.Expression.Null as X
214import Squeal.PostgreSQL.Expression.Null as X
215import Squeal.PostgreSQL.Expression.Parameter as X
215import Squeal.PostgreSQL.Expression.Parameter as X
216import Squeal.PostgreSQL.Expression.Range as X
216import Squeal.PostgreSQL.Expression.Range as X
217−import Squeal.PostgreSQL.Expression.SetOf as X
217+import Squeal.PostgreSQL.Expression.Set as X
218import Squeal.PostgreSQL.Expression.Sort as X
218import Squeal.PostgreSQL.Expression.Sort as X
219import Squeal.PostgreSQL.Expression.Subquery as X
219import Squeal.PostgreSQL.Expression.Subquery as X
220import Squeal.PostgreSQL.Expression.Text as X
220import 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
42
42
43import Squeal.PostgreSQL.Alias
43import Squeal.PostgreSQL.Alias
44import Squeal.PostgreSQL.Expression
44import Squeal.PostgreSQL.Expression
45−import Squeal.PostgreSQL.Expression.SetOf
45+import Squeal.PostgreSQL.Expression.Set
46import Squeal.PostgreSQL.List
46import Squeal.PostgreSQL.List
47import Squeal.PostgreSQL.Render
47import Squeal.PostgreSQL.Render
48import Squeal.PostgreSQL.Schema
48import Squeal.PostgreSQL.Schema
@@ -123,8 +123,8 @@ index n expr = UnsafeExpression $
123 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
123 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
124
124
125-- | Expand an array to a set of rows
125-- | Expand an array to a set of rows
126−unnest :: SetOfFunction "unnest" (null ('PGvararray ty)) '["unnest" ::: ty]
126+unnest :: SetFunction "unnest" (null ('PGvararray ty)) '["unnest" ::: ty]
127−unnest = unsafeSetOfFunction
127+unnest = unsafeSetFunction
128
128
129-- | A row constructor is an expression that builds a row value
129-- | A row constructor is an expression that builds a row value
130-- (also called a composite value) using values for its member fields.
130-- (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
81
81
82import Squeal.PostgreSQL.Alias
82import Squeal.PostgreSQL.Alias
83import Squeal.PostgreSQL.Expression
83import Squeal.PostgreSQL.Expression
84−import Squeal.PostgreSQL.Expression.SetOf
84+import Squeal.PostgreSQL.Expression.Set
85import Squeal.PostgreSQL.Expression.Type
85import Squeal.PostgreSQL.Expression.Type
86import Squeal.PostgreSQL.List
86import Squeal.PostgreSQL.List
87import Squeal.PostgreSQL.Query
87import Squeal.PostgreSQL.Query
@@ -337,9 +337,9 @@ jsonbPretty = unsafeFunction "jsonb_pretty"
337>>> printSQL (select Star (from (jsonEach (literal (Json (object ["a" .= "foo", "b" .= "bar"]))))))
337>>> printSQL (select Star (from (jsonEach (literal (Json (object ["a" .= "foo", "b" .= "bar"]))))))
338SELECT * FROM json_each(('{"a":"foo","b":"bar"}' :: json))
338SELECT * FROM json_each(('{"a":"foo","b":"bar"}' :: json))
339-}
339-}
340−jsonEach :: SetOfFunction "json_each" (null 'PGjson)
340+jsonEach :: SetFunction "json_each" (null 'PGjson)
341 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
341 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
342−jsonEach = unsafeSetOfFunction
342+jsonEach = unsafeSetFunction
343
343
344{- | Expands the outermost binary JSON object into a set of key/value pairs.
344{- | Expands the outermost binary JSON object into a set of key/value pairs.
345
345
@@ -347,9 +347,9 @@ jsonEach = unsafeSetOfFunction
347SELECT * FROM jsonb_each(('{"a":"foo","b":"bar"}' :: jsonb))
347SELECT * FROM jsonb_each(('{"a":"foo","b":"bar"}' :: jsonb))
348-}
348-}
349jsonbEach
349jsonbEach
350− :: SetOfFunction "jsonb_each" (nullity 'PGjsonb)
350+ :: SetFunction "jsonb_each" (nullity 'PGjsonb)
351 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
351 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
352−jsonbEach = unsafeSetOfFunction
352+jsonbEach = unsafeSetFunction
353
353
354{- | Expands the outermost JSON object into a set of key/value pairs.
354{- | Expands the outermost JSON object into a set of key/value pairs.
355
355
@@ -357,9 +357,9 @@ jsonbEach = unsafeSetOfFunction
357SELECT * FROM json_each_text(('{"a":"foo","b":"bar"}' :: json))
357SELECT * FROM json_each_text(('{"a":"foo","b":"bar"}' :: json))
358-}
358-}
359jsonEachText
359jsonEachText
360− :: SetOfFunction "json_each_text" (null 'PGjson)
360+ :: SetFunction "json_each_text" (null 'PGjson)
361 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
361 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
362−jsonEachText = unsafeSetOfFunction
362+jsonEachText = unsafeSetFunction
363
363
364{- | Expands the outermost binary JSON object into a set of key/value pairs.
364{- | Expands the outermost binary JSON object into a set of key/value pairs.
365
365
@@ -367,9 +367,9 @@ jsonEachText = unsafeSetOfFunction
367SELECT * FROM jsonb_each_text(('{"a":"foo","b":"bar"}' :: jsonb))
367SELECT * FROM jsonb_each_text(('{"a":"foo","b":"bar"}' :: jsonb))
368-}
368-}
369jsonbEachText
369jsonbEachText
370− :: SetOfFunction "jsonb_each_text" (null 'PGjsonb)
370+ :: SetFunction "jsonb_each_text" (null 'PGjsonb)
371 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
371 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
372−jsonbEachText = unsafeSetOfFunction
372+jsonbEachText = unsafeSetFunction
373
373
374{- | Returns set of keys in the outermost JSON object.
374{- | Returns set of keys in the outermost JSON object.
375
375
@@ -377,9 +377,9 @@ jsonbEachText = unsafeSetOfFunction
377json_object_keys(('{"a":"foo","b":"bar"}' :: json))
377json_object_keys(('{"a":"foo","b":"bar"}' :: json))
378-}
378-}
379jsonObjectKeys
379jsonObjectKeys
380− :: SetOfFunction "json_object_keys" (nullity 'PGjson)
380+ :: SetFunction "json_object_keys" (nullity 'PGjson)
381 '["json_object_keys" ::: 'NotNull 'PGtext]
381 '["json_object_keys" ::: 'NotNull 'PGtext]
382−jsonObjectKeys = unsafeSetOfFunction
382+jsonObjectKeys = unsafeSetFunction
383
383
384{- | Returns set of keys in the outermost JSON object.
384{- | Returns set of keys in the outermost JSON object.
385
385
@@ -387,9 +387,9 @@ jsonObjectKeys = unsafeSetOfFunction
387jsonb_object_keys(('{"a":"foo","b":"bar"}' :: jsonb))
387jsonb_object_keys(('{"a":"foo","b":"bar"}' :: jsonb))
388-}
388-}
389jsonbObjectKeys
389jsonbObjectKeys
390− :: SetOfFunction "jsonb_object_keys" (null 'PGjsonb)
390+ :: SetFunction "jsonb_object_keys" (null 'PGjsonb)
391 '["jsonb_object_keys" ::: 'NotNull 'PGtext]
391 '["jsonb_object_keys" ::: 'NotNull 'PGtext]
392−jsonbObjectKeys = unsafeSetOfFunction
392+jsonbObjectKeys = unsafeSetFunction
393
393
394-- | Build rows from Json types.
394-- | Build rows from Json types.
395type JsonPopulateFunction fun json
395type 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 @@
1{-|
1{-|
2−Module: Squeal.PostgreSQL.Expression.SetOf
2+Module: Squeal.PostgreSQL.Expression.Set
3Description: Set returning functions
3Description: Set returning functions
4Copyright: (c) Eitan Chatav, 2019
4Copyright: (c) Eitan Chatav, 2019
5Maintainer: eitan@morphism.tech
5Maintainer: eitan@morphism.tech
@@ -20,17 +20,17 @@ Set returning functions
20 , TypeOperators
20 , TypeOperators
21#-}
21#-}
22
22
23−module Squeal.PostgreSQL.Expression.SetOf
23+module Squeal.PostgreSQL.Expression.Set
24 ( generateSeries
24 ( generateSeries
25 , generateSeriesStep
25 , generateSeriesStep
26 , generateSeriesTimestamp
26 , generateSeriesTimestamp
27− , SetOfFunction
27+ , SetFunction
28− , unsafeSetOfFunction
28+ , unsafeSetFunction
29− , SetOfFunctionDB
29+ , SetFunctionDB
30 , setOfFunction
30 , setOfFunction
31− , SetOfFunctionN
31+ , SetFunctionN
32− , unsafeSetOfFunctionN
32+ , unsafeSetFunctionN
33− , SetOfFunctionNDB
33+ , SetFunctionNDB
34 , setOfFunctionN
34 , setOfFunctionN
35 ) where
35 ) where
36
36
@@ -48,65 +48,65 @@ import Squeal.PostgreSQL.Schema
48{- |
48{- |
49A @RankNType@ for set returning functions with 1 argument.
49A @RankNType@ for set returning functions with 1 argument.
50-}
50-}
51−type SetOfFunction fun ty setof
51+type SetFunction fun ty row
52 = forall outer commons schemas params
52 = forall outer commons schemas params
53 . Expression outer commons 'Ungrouped schemas params '[] ty
53 . Expression outer commons 'Ungrouped schemas params '[] ty
54 -- ^ input
54 -- ^ input
55− -> FromClause outer commons schemas params '[fun ::: setof]
55+ -> FromClause outer commons schemas params '[fun ::: row]
56 -- ^ output
56 -- ^ output
57
57
58−type SetOfFunctionDB fun schemas ty setof
58+type SetFunctionDB fun schemas ty row
59 = forall outer commons params
59 = forall outer commons params
60 . Expression outer commons 'Ungrouped schemas params '[] ty
60 . Expression outer commons 'Ungrouped schemas params '[] ty
61 -- ^ input
61 -- ^ input
62− -> FromClause outer commons schemas params '[fun ::: setof]
62+ -> FromClause outer commons schemas params '[fun ::: row]
63 -- ^ output
63 -- ^ output
64
64
65-- | Escape hatch for a set returning function with 1 argument.
65-- | Escape hatch for a set returning function with 1 argument.
66−unsafeSetOfFunction
66+unsafeSetFunction
67− :: forall fun ty setof. KnownSymbol fun
67+ :: forall fun ty row. KnownSymbol fun
68− => SetOfFunction fun ty setof -- ^ set returning function
68+ => SetFunction fun ty row -- ^ set returning function
69−unsafeSetOfFunction x = UnsafeFromClause $
69+unsafeSetFunction x = UnsafeFromClause $
70 renderSymbol @fun <> parenthesized (renderSQL x)
70 renderSymbol @fun <> parenthesized (renderSQL x)
71
71
72setOfFunction
72setOfFunction
73 :: ( Has sch schemas schema
73 :: ( Has sch schemas schema
74− , Has fun schema ('Function ('[ty] :=> 'ReturnsTable setof)) )
74+ , Has fun schema ('Function ('[ty] :=> 'ReturnsTable row)) )
75 => QualifiedAlias sch fun
75 => QualifiedAlias sch fun
76− -> SetOfFunctionDB fun schemas ty setof
76+ -> SetFunctionDB fun schemas ty row
77−setOfFunction _ = unsafeSetOfFunction
77+setOfFunction _ = unsafeSetFunction
78
78
79{- |
79{- |
80A @RankNType@ for set returning functions with multiple argument.
80A @RankNType@ for set returning functions with multiple argument.
81-}
81-}
82−type SetOfFunctionN fun tys setof
82+type SetFunctionN fun tys row
83 = forall outer commons schemas params
83 = forall outer commons schemas params
84 . NP (Expression outer commons 'Ungrouped schemas params '[]) tys
84 . NP (Expression outer commons 'Ungrouped schemas params '[]) tys
85 -- ^ inputs
85 -- ^ inputs
86− -> FromClause outer commons schemas params '[fun ::: setof]
86+ -> FromClause outer commons schemas params '[fun ::: row]
87 -- ^ output
87 -- ^ output
88
88
89-- | Escape hatch for a set returning function with multiple argument.
89-- | Escape hatch for a set returning function with multiple argument.
90−unsafeSetOfFunctionN
90+unsafeSetFunctionN
91− :: forall fun tys setof. (SOP.SListI tys, KnownSymbol fun)
91+ :: forall fun tys row. (SOP.SListI tys, KnownSymbol fun)
92− => SetOfFunctionN fun tys setof -- ^ set returning function
92+ => SetFunctionN fun tys row -- ^ set returning function
93−unsafeSetOfFunctionN xs = UnsafeFromClause $
93+unsafeSetFunctionN xs = UnsafeFromClause $
94 renderSymbol @fun <> parenthesized (renderCommaSeparated renderSQL xs)
94 renderSymbol @fun <> parenthesized (renderCommaSeparated renderSQL xs)
95
95
96−type SetOfFunctionNDB fun schemas tys setof
96+type SetFunctionNDB fun schemas tys row
97 = forall outer commons params
97 = forall outer commons params
98 . NP (Expression outer commons 'Ungrouped schemas params '[]) tys
98 . NP (Expression outer commons 'Ungrouped schemas params '[]) tys
99 -- ^ inputs
99 -- ^ inputs
100− -> FromClause outer commons schemas params '[fun ::: setof]
100+ -> FromClause outer commons schemas params '[fun ::: row]
101 -- ^ output
101 -- ^ output
102
102
103setOfFunctionN
103setOfFunctionN
104 :: ( Has sch schemas schema
104 :: ( Has sch schemas schema
105− , Has fun schema ('Function (tys :=> 'ReturnsTable setof))
105+ , Has fun schema ('Function (tys :=> 'ReturnsTable row))
106 , SOP.SListI tys )
106 , SOP.SListI tys )
107 => QualifiedAlias sch fun
107 => QualifiedAlias sch fun
108− -> SetOfFunctionNDB fun schemas tys setof
108+ -> SetFunctionNDB fun schemas tys row
109−setOfFunctionN _ = unsafeSetOfFunctionN
109+setOfFunctionN _ = unsafeSetFunctionN
110
110
111{- | @generateSeries (start *: stop)@
111{- | @generateSeries (start *: stop)@
112
112
@@ -114,9 +114,9 @@ Generate a series of values, from @start@ to @stop@ with a step size of one
114-}
114-}
115generateSeries
115generateSeries
116 :: ty `In` '[ 'PGint4, 'PGint8, 'PGnumeric]
116 :: ty `In` '[ 'PGint4, 'PGint8, 'PGnumeric]
117− => SetOfFunctionN "generate_series" '[ null ty, null ty]
117+ => SetFunctionN "generate_series" '[ null ty, null ty]
118 '["generate_series" ::: null ty] -- ^ set returning function
118 '["generate_series" ::: null ty] -- ^ set returning function
119−generateSeries = unsafeSetOfFunctionN
119+generateSeries = unsafeSetFunctionN
120
120
121{- | @generateSeries (start :* stop *: step)@
121{- | @generateSeries (start :* stop *: step)@
122
122
@@ -124,9 +124,9 @@ Generate a series of values, from @start@ to @stop@ with a step size of @step@
124-}
124-}
125generateSeriesStep
125generateSeriesStep
126 :: ty `In` '[ 'PGint4, 'PGint8, 'PGnumeric]
126 :: 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]
128 '["generate_series" ::: null ty] -- ^ set returning function
128 '["generate_series" ::: null ty] -- ^ set returning function
129−generateSeriesStep = unsafeSetOfFunctionN
129+generateSeriesStep = unsafeSetFunctionN
130
130
131{- | @generateSeries (start :* stop *: step)@
131{- | @generateSeries (start :* stop *: step)@
132
132
@@ -134,6 +134,6 @@ Generate a series of values, from @start@ to @stop@ with a step size of @step@
134-}
134-}
135generateSeriesTimestamp
135generateSeriesTimestamp
136 :: ty `In` '[ 'PGtimestamp, 'PGtimestamptz]
136 :: ty `In` '[ 'PGtimestamp, 'PGtimestamptz]
137− => SetOfFunctionN "generate_series" '[null ty, null ty, null 'PGinterval]
137+ => SetFunctionN "generate_series" '[null ty, null ty, null 'PGinterval]
138 '["generate_series" ::: null ty] -- ^ set returning function
138 '["generate_series" ::: null ty] -- ^ set returning function
139−generateSeriesTimestamp = unsafeSetOfFunctionN
139+generateSeriesTimestamp = unsafeSetFunctionN