on dev help sign in
some last fixes
c8bd2bfEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL.hs+5−4
@@ -28,7 +28,7 @@
28-- >
28-- >
29-- > import Squeal.PostgreSQL
29-- > import Squeal.PostgreSQL
30--
30--
31−-- We'll use generics to easily convert between Haskell of PostgreSQL values.
31+-- We'll use generics to easily convert between Haskell and PostgreSQL values.
32--
32--
33-- > import qualified Generics.SOP as SOP
33-- > import qualified Generics.SOP as SOP
34-- > import qualified GHC.Generics as GHC
34-- > import qualified GHC.Generics as GHC
@@ -89,10 +89,11 @@
89-- has three type parameters, the schema it refers to, a list of parameters
89-- has three type parameters, the schema it refers to, a list of parameters
90-- it can take as input, and a list of columns it produces as output. When
90-- it can take as input, and a list of columns it produces as output. When
91-- we insert into the users table, we will need a parameter for the @name@
91-- we insert into the users table, we will need a parameter for the @name@
92−-- field but not for the @id@ field since it's optional, we can use a default
92+-- field but not for the @id@ field. Since it's optional, we can use a default
93-- value. However, since the emails table refers to the users table, we will
93-- value. However, since the emails table refers to the users table, we will
94−-- need to retrieve the user id and insert it into the emails table. Take
94+-- need to retrieve the user id that the insert generates and insert it into
95−-- a careful look at the type and definition of both of our inserts.
95+-- the emails table. Take a careful look at the type and definition of both
96+-- of our inserts.
96--
97--
97-- > insertUser :: Manipulation Schema
98-- > insertUser :: Manipulation Schema
98-- > '[ 'Required ('NotNull 'PGtext)]
99-- > '[ 'Required ('NotNull 'PGtext)]
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+9−13
@@ -140,11 +140,7 @@ let
140 query :: Query '["tab" ::: '["col" ::: 'Required ('Null 'PGint4)]] '[]
140 query :: Query '["tab" ::: '["col" ::: 'Required ('Null 'PGint4)]] '[]
141 '["col" ::: 'Required ('Null 'PGint4)]
141 '["col" ::: 'Required ('Null 'PGint4)]
142 query = selectStar
142 query = selectStar
143− ( from (Table (#tab `As` #t))
143+ (from (Table (#tab `As` #t)) & limit 100 & offset 2 & limit 50 & offset 2)
144− & limit 100
145− & offset 2
146− & limit 50
147− & offset 2 )
148in renderQuery query
144in renderQuery query
149:}
145:}
150"SELECT * FROM tab AS t LIMIT 50 OFFSET 4"
146"SELECT * FROM tab AS t LIMIT 50 OFFSET 4"
@@ -153,14 +149,14 @@ parameterized query:
153
149
154>>> :{
150>>> :{
155let
151let
156− query :: Query '["tab" ::: '["col" ::: 'Required ('Null 'PGint4)]]
152+ query :: Query '["tab" ::: '["col" ::: 'Required ('NotNull 'PGfloat8)]]
157− '[ 'Required ('NotNull 'PGbool)]
153+ '[ 'Required ('NotNull 'PGfloat8)]
158− '["col" ::: 'Required ('Null 'PGint4)]
154+ '["col" ::: 'Required ('NotNull 'PGfloat8)]
159 query = selectStar
155 query = selectStar
160− (from (Table (#tab `As` #t)) & where_ (param @1))
156+ (from (Table (#tab `As` #t)) & where_ (#col .> param @1))
161in renderQuery query
157in renderQuery query
162:}
158:}
163−"SELECT * FROM tab AS t WHERE ($1 :: bool)"
159+"SELECT * FROM tab AS t WHERE (col > ($1 :: float8))"
164
160
165aggregation query:
161aggregation query:
166
162
@@ -202,7 +198,7 @@ let
202 query :: Query
198 query :: Query
203 '[ "orders" :::
199 '[ "orders" :::
204 '[ "id" ::: 'Required ('NotNull 'PGint4)
200 '[ "id" ::: 'Required ('NotNull 'PGint4)
205− , "order_price" ::: 'Required ('NotNull 'PGfloat4)
201+ , "price" ::: 'Required ('NotNull 'PGfloat4)
206 , "customer_id" ::: 'Required ('NotNull 'PGint4)
202 , "customer_id" ::: 'Required ('NotNull 'PGint4)
207 , "shipper_id" ::: 'Required ('NotNull 'PGint4)
203 , "shipper_id" ::: 'Required ('NotNull 'PGint4)
208 ]
204 ]
@@ -221,7 +217,7 @@ let
221 , "shipper_name" ::: 'Required ('NotNull 'PGtext)
217 , "shipper_name" ::: 'Required ('NotNull 'PGtext)
222 ]
218 ]
223 query = select
219 query = select
224− ( #o ! #order_price `As` #order_price :*
220+ ( #o ! #price `As` #order_price :*
225 #c ! #name `As` #customer_name :*
221 #c ! #name `As` #customer_name :*
226 #s ! #name `As` #shipper_name :* Nil )
222 #s ! #name `As` #shipper_name :* Nil )
227 ( from (Table (#orders `As` #o)
223 ( from (Table (#orders `As` #o)
@@ -231,7 +227,7 @@ let
231 (#o ! #shipper_id .== #s ! #id)) )
227 (#o ! #shipper_id .== #s ! #id)) )
232in renderQuery query
228in renderQuery query
233:}
229:}
234−"SELECT o.order_price AS order_price, c.name AS customer_name, s.name AS shipper_name FROM orders AS o INNER JOIN customers AS c ON (o.customer_id = c.id) INNER JOIN shippers AS s ON (o.shipper_id = s.id)"
230+"SELECT o.price AS order_price, c.name AS customer_name, s.name AS shipper_name FROM orders AS o INNER JOIN customers AS c ON (o.customer_id = c.id) INNER JOIN shippers AS s ON (o.shipper_id = s.id)"
235
231
236self-join:
232self-join:
237
233