@@ -99,9 +99,9 @@ let
100 '["col" ::: 'Null 'PGint4]
100 '["col" ::: 'Null 'PGint4]
101 query = selectStar (from (table #tab))
101 query = selectStar (from (table #tab))
102−in renderQuery query
102+in printSQL query
104−"SELECT * FROM \"tab\" AS \"tab\""
104+SELECT * FROM "tab" AS "tab"
106restricted query:
106restricted query:
@@ -120,9 +120,9 @@ let
120 ( from (table #tab)
120 ( from (table #tab)
121 & where_ (#col1 .> #col2)
121 & where_ (#col1 .> #col2)
122 & where_ (#col2 .> 0) )
122 & where_ (#col2 .> 0) )
123−in renderQuery query
123+in printSQL query
125−"SELECT (\"col1\" + \"col2\") AS \"sum\", \"col1\" AS \"col1\" FROM \"tab\" AS \"tab\" WHERE ((\"col1\" > \"col2\") AND (\"col2\" > 0))"
125+SELECT ("col1" + "col2") AS "sum", "col1" AS "col1" FROM "tab" AS "tab" WHERE (("col1" > "col2") AND ("col2" > 0))
@@ -135,9 +135,9 @@ let
136 selectStar
136 selectStar
137 (from (subquery (selectStar (from (table #tab)) `As` #sub)))
137 (from (subquery (selectStar (from (table #tab)) `As` #sub)))
138−in renderQuery query
138+in printSQL query
140−"SELECT * FROM (SELECT * FROM \"tab\" AS \"tab\") AS \"sub\""
140+SELECT * FROM (SELECT * FROM "tab" AS "tab") AS "sub"
142limits and offsets:
142limits and offsets:
@@ -149,9 +149,9 @@ let
149 '["col" ::: 'Null 'PGint4]
149 '["col" ::: 'Null 'PGint4]
150 query = selectStar
150 query = selectStar
151 (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)
151 (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)
152−in renderQuery query
152+in printSQL query
154−"SELECT * FROM \"tab\" AS \"tab\" LIMIT 50 OFFSET 4"
154+SELECT * FROM "tab" AS "tab" LIMIT 50 OFFSET 4
156parameterized query:
156parameterized query:
@@ -163,9 +163,9 @@ let
163 '["col" ::: 'NotNull 'PGfloat8]
163 '["col" ::: 'NotNull 'PGfloat8]
164 query = selectStar
164 query = selectStar
165 (from (table #tab) & where_ (#col .> param @1))
165 (from (table #tab) & where_ (#col .> param @1))
166−in renderQuery query
166+in printSQL query
168−"SELECT * FROM \"tab\" AS \"tab\" WHERE (\"col\" > ($1 :: float8))"
168+SELECT * FROM "tab" AS "tab" WHERE ("col" > ($1 :: float8))
170aggregation query:
170aggregation query:
@@ -183,9 +183,9 @@ let
183 ( from (table (#tab `As` #table1))
183 ( from (table (#tab `As` #table1))
184 & group (By #col1 :* Nil)
184 & group (By #col1 :* Nil)
185 & having (#col1 + sum_ #col2 .> 1) )
185 & having (#col1 + sum_ #col2 .> 1) )
186−in renderQuery query
186+in printSQL query
188−"SELECT sum(\"col2\") AS \"sum\", \"col1\" AS \"col1\" FROM \"tab\" AS \"table1\" GROUP BY \"col1\" HAVING ((\"col1\" + sum(\"col2\")) > 1)"
188+SELECT sum("col2") AS "sum", "col1" AS "col1" FROM "tab" AS "table1" GROUP BY "col1" HAVING (("col1" + sum("col2")) > 1)
190sorted query:
190sorted query:
@@ -197,9 +197,9 @@ let
197 '["col" ::: 'Null 'PGint4]
197 '["col" ::: 'Null 'PGint4]
198 query = selectStar
198 query = selectStar
199 (from (table #tab) & orderBy [#col & AscNullsFirst])
199 (from (table #tab) & orderBy [#col & AscNullsFirst])
200−in renderQuery query
200+in printSQL query
202−"SELECT * FROM \"tab\" AS \"tab\" ORDER BY \"col\" ASC NULLS FIRST"
202+SELECT * FROM "tab" AS "tab" ORDER BY "col" ASC NULLS FIRST
@@ -241,9 +241,9 @@ let
241 (#o ! #customer_id .== #c ! #id)
241 (#o ! #customer_id .== #c ! #id)
242 & innerJoin (table (#shippers `As` #s))
242 & innerJoin (table (#shippers `As` #s))
243 (#o ! #shipper_id .== #s ! #id)) )
243 (#o ! #shipper_id .== #s ! #id)) )
244−in renderQuery query
244+in printSQL query
246−"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\")"
246+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")
248self-join:
248self-join:
@@ -255,9 +255,9 @@ let
255 '["col" ::: 'Null 'PGint4]
255 '["col" ::: 'Null 'PGint4]
256 query = selectDotStar #t1
256 query = selectDotStar #t1
257 (from (table (#tab `As` #t1) & crossJoin (table (#tab `As` #t2))))
257 (from (table (#tab `As` #t1) & crossJoin (table (#tab `As` #t2))))
258−in renderQuery query
258+in printSQL query
260−"SELECT \"t1\".* FROM \"tab\" AS \"t1\" CROSS JOIN \"tab\" AS \"t2\""
260+SELECT "t1".* FROM "tab" AS "t1" CROSS JOIN "tab" AS "t2"
262set operations:
262set operations:
@@ -271,9 +271,9 @@ let
271 selectStar (from (table #tab))
271 selectStar (from (table #tab))
272 `unionAll`
272 `unionAll`
273 selectStar (from (table #tab))
273 selectStar (from (table #tab))
274−in renderQuery query
274+in printSQL query
276−"(SELECT * FROM \"tab\" AS \"tab\") UNION ALL (SELECT * FROM \"tab\" AS \"tab\")"
276+(SELECT * FROM "tab" AS "tab") UNION ALL (SELECT * FROM "tab" AS "tab")
278newtype Query
278newtype Query
279 (schema :: SchemaType)
279 (schema :: SchemaType)
@@ -281,6 +281,7 @@ newtype Query
281 (columns :: RelationType)
281 (columns :: RelationType)
282 = UnsafeQuery { renderQuery :: ByteString }
282 = UnsafeQuery { renderQuery :: ByteString }
283 deriving (GHC.Generic,Show,Eq,Ord,NFData)
283 deriving (GHC.Generic,Show,Eq,Ord,NFData)
284+instance RenderSQL (Query schema params columns) where renderSQL = renderQuery
285-- | The results of two queries can be combined using the set operation
286-- | The results of two queries can be combined using the set operation
286-- `union`. Duplicate rows are eliminated.
287-- `union`. Duplicate rows are eliminated.
@@ -434,8 +435,8 @@ selectDistinctDotStar rel relations = UnsafeQuery $
435-- >>> type Row = '["a" ::: 'NotNull 'PGint4, "b" ::: 'NotNull 'PGtext]
436-- >>> type Row = '["a" ::: 'NotNull 'PGint4, "b" ::: 'NotNull 'PGtext]
436-- >>> let query = values (1 `As` #a :* "one" `As` #b :* Nil) [] :: Query '[] '[] Row
437-- >>> let query = values (1 `As` #a :* "one" `As` #b :* Nil) [] :: Query '[] '[] Row
437−-- >>> renderQuery query
438+-- >>> printSQL query
438−-- "SELECT * FROM (VALUES (1, E'one')) AS t (\"a\", \"b\")"
439+-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
440 :: SListI cols
441 :: SListI cols
441 => NP (Aliased (Expression schema '[] 'Ungrouped params)) cols
442 => NP (Aliased (Expression schema '[] 'Ungrouped params)) cols