on dev help sign in
some last fixes
commitc8bd2bf56e0d7d11d9956ccc01f27355800c2baa authorEitan Chatav <eitan.chatav@gmail.com> dateTue 29 Aug 2017, 13:31 (9 years ago) parent456d103
2 files changed+14−17
squeal-postgresql/src/Squeal/PostgreSQL.hs+5−4 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+9−13
squeal-postgresql/src/Squeal/PostgreSQL.hs+5−4
@@ -28,7 +28,7 @@
2828-- >
2929-- > import Squeal.PostgreSQL
3030--
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.
3232--
3333-- > import qualified Generics.SOP as SOP
3434-- > import qualified GHC.Generics as GHC
@@ -89,10 +89,11 @@
8989-- has three type parameters, the schema it refers to, a list of parameters
9090-- it can take as input, and a list of columns it produces as output. When
9191-- 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
9393-- 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
95−-- a careful look at the type and definition of both of our inserts.
94+-- need to retrieve the user id that the insert generates and insert it into
95+-- the emails table. Take a careful look at the type and definition of both
96+-- of our inserts.
9697--
9798-- > insertUser :: Manipulation Schema
9899-- > '[ 'Required ('NotNull 'PGtext)]
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+9−13
@@ -140,11 +140,7 @@ let
140140 query :: Query '["tab" ::: '["col" ::: 'Required ('Null 'PGint4)]] '[]
141141 '["col" ::: 'Required ('Null 'PGint4)]
142142 query = selectStar
143− ( from (Table (#tab `As` #t))
144− & limit 100
145− & offset 2
146− & limit 50
147− & offset 2 )
143+ (from (Table (#tab `As` #t)) & limit 100 & offset 2 & limit 50 & offset 2)
148144in renderQuery query
149145:}
150146"SELECT * FROM tab AS t LIMIT 50 OFFSET 4"
@@ -153,14 +149,14 @@ parameterized query:
153149
154150>>> :{
155151let
156− query :: Query '["tab" ::: '["col" ::: 'Required ('Null 'PGint4)]]
157− '[ 'Required ('NotNull 'PGbool)]
158− '["col" ::: 'Required ('Null 'PGint4)]
152+ query :: Query '["tab" ::: '["col" ::: 'Required ('NotNull 'PGfloat8)]]
153+ '[ 'Required ('NotNull 'PGfloat8)]
154+ '["col" ::: 'Required ('NotNull 'PGfloat8)]
159155 query = selectStar
160− (from (Table (#tab `As` #t)) & where_ (param @1))
156+ (from (Table (#tab `As` #t)) & where_ (#col .> param @1))
161157in renderQuery query
162158:}
163−"SELECT * FROM tab AS t WHERE ($1 :: bool)"
159+"SELECT * FROM tab AS t WHERE (col > ($1 :: float8))"
164160
165161aggregation query:
166162
@@ -202,7 +198,7 @@ let
202198 query :: Query
203199 '[ "orders" :::
204200 '[ "id" ::: 'Required ('NotNull 'PGint4)
205− , "order_price" ::: 'Required ('NotNull 'PGfloat4)
201+ , "price" ::: 'Required ('NotNull 'PGfloat4)
206202 , "customer_id" ::: 'Required ('NotNull 'PGint4)
207203 , "shipper_id" ::: 'Required ('NotNull 'PGint4)
208204 ]
@@ -221,7 +217,7 @@ let
221217 , "shipper_name" ::: 'Required ('NotNull 'PGtext)
222218 ]
223219 query = select
224− ( #o ! #order_price `As` #order_price :*
220+ ( #o ! #price `As` #order_price :*
225221 #c ! #name `As` #customer_name :*
226222 #s ! #name `As` #shipper_name :* Nil )
227223 ( from (Table (#orders `As` #o)
@@ -231,7 +227,7 @@ let
231227 (#o ! #shipper_id .== #s ! #id)) )
232228in renderQuery query
233229:}
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)"
235231
236232self-join:
237233