@@ -64,23 +64,27 @@ spec = do
64 ("Robert'); DROP TABLE students;" `As` #name :& RNil)
64 ("Robert'); DROP TABLE students;" `As` #name :& RNil)
65 `shouldRenderAs`
65 `shouldRenderAs`
66 "INSERT INTO students (name) VALUES (E'Robert''); DROP TABLE students;');"
66 "INSERT INTO students (name) VALUES (E'Robert''); DROP TABLE students;');"
67− -- describe "JOINs" $ do
67+ describe "JOINs" $ do
68− -- it "should render CROSS JOINs" $
68+ it "should render CROSS JOINs" $ do
70− -- it "should render INNER JOINs" $ do
71− -- select (vals `from` joinTable) `shouldRenderAs`
69+ select (vals `from` crossJoins) `shouldRenderAs`
72− -- "((orders\
70+ "SELECT\
73− -- \ INNER JOIN customers ON orders.customerID = customers.customerID)\
71+ \ orders.orderVal AS orderVal,\
74− -- \ INNER JOIN shippers ON orders.shipperID = shippers.shipperID)"
72+ \ customers.customerVal AS customerVal,\
75−-- #orders
73+ \ shippers.shipperVal AS shipperVal\
76−-- & innerJoin #customers
74+ \ FROM orders\
77−-- (#orders .&. #customerID ==* #customers .&. #customerID)
75+ \ CROSS JOIN customers\
78−-- & innerJoin #shippers
76+ \ CROSS JOIN shippers;"
79−-- (#orders .&. #shipperID ==* #shippers .&. #shipperID)
77+ it "should render INNER JOINs" $ do
80−-- `shouldRenderAs`
78+ select (vals `from` innerJoins) `shouldRenderAs`
80+ \ orders.orderVal AS orderVal,\
81+ \ customers.customerVal AS customerVal,\
82+ \ shippers.shipperVal AS shipperVal\
81−-- "((orders\
83+ \ FROM orders\
84+ \ INNER JOIN customers\
82−-- \ INNER JOIN customers ON orders.customerID = customers.customerID)\
85+ \ ON (orders.customerID = customers.customerID)\
86+ \ INNER JOIN shippers\
83−-- \ INNER JOIN shippers ON orders.shipperID = shippers.shipperID)"
87+ \ ON (orders.shipperID = shippers.shipperID);"
85type Columns = '[ "col1" ::: 'PGInt4, "col2" ::: 'PGInt4]
89type Columns = '[ "col1" ::: 'PGInt4, "col2" ::: 'PGInt4]
86type Tables = '[ "table1" ::: Columns ]
90type Tables = '[ "table1" ::: Columns ]
@@ -110,30 +114,37 @@ type StudentsColumns = '["name" ::: 'PGText]
110type StudentsTable = '["students" ::: StudentsColumns]
114type StudentsTable = '["students" ::: StudentsColumns]
112type OrderColumns =
116type OrderColumns =
117+ [ "orderID" ::: 'PGInt4
113− [ "orderID" ::: 'PGInt4, "orderVal" ::: 'PGText ]
118+ , "orderVal" ::: 'PGText
119+ , "customerID" ::: 'PGInt4
120+ , "shipperID" ::: 'PGInt4
114type CustomerColumns =
122type CustomerColumns =
115 [ "customerID" ::: 'PGInt4, "customerVal" ::: 'PGFloat4 ]
123 [ "customerID" ::: 'PGInt4, "customerVal" ::: 'PGFloat4 ]
116type ShipperColumns =
124type ShipperColumns =
117 [ "shipperID" ::: 'PGInt4, "shipperVal" ::: 'PGBool ]
125 [ "shipperID" ::: 'PGInt4, "shipperVal" ::: 'PGBool ]
118type JoinTables =
126type JoinTables =
127+ [ "shippers" ::: ShipperColumns
128+ , "customers" ::: CustomerColumns
119− [ "order" ::: OrderColumns
129+ , "orders" ::: OrderColumns
120− , "customer" ::: CustomerColumns
121− , "shipper" ::: ShipperColumns
123type ValueColumns =
131type ValueColumns =
124 [ "orderVal" ::: 'PGText
132 [ "orderVal" ::: 'PGText
125 , "customerVal" ::: 'PGFloat4
133 , "customerVal" ::: 'PGFloat4
126 , "shipperVal" ::: 'PGBool
134 , "shipperVal" ::: 'PGBool
128−-- vals :: Projection '[] JoinTables ValueColumns
136+vals :: Projection '[] JoinTables ValueColumns
129−-- vals = project $
137+vals = project $
130−-- #orders .&. #orderVal `As` #orderVal
138+ #orders .&. #orderVal `As` #orderVal
131−-- :& #customers .&. #customerVal `As` #customerVal
139+ :& #customers .&. #customerVal `As` #customerVal
132−-- :& #shippers .&. #shippersVal `As` #shippersVal :& RNil
140+ :& #shippers .&. #shipperVal `As` #shipperVal :& RNil
133−-- joinTable :: Tabulation '[] JoinTables JoinTables
141+crossJoins :: Tabulation '[] JoinTables JoinTables
142+crossJoins = tabulation $
143+ #orders & crossJoin #customers & crossJoin #shippers
144+innerJoins :: Tabulation '[] JoinTables JoinTables
134−-- joinTable = tabulation $
145+innerJoins = tabulation $
135−-- #orders
146+ #orders
136−-- & innerJoin #customers
147+ & innerJoin #customers
137−-- (#orders .&. #customerID ==* #customers .&. #customerID)
148+ (#orders .&. #customerID ==* #customers .&. #customerID)
138−-- & innerJoin #shippers
149+ & innerJoin #shippers
139−-- (#orders .&. #shipperID ==* #shippers .&. #shipperID)
150+ (#orders .&. #shipperID ==* #shippers .&. #shipperID)