@@ -6,7 +6,7 @@
66 , TypeOperators
77#-}
88
9−module Squeel.PostgreSQL.QuerySpec where
9+module Squeel.PostgreSQL.StatementSpec where
1010
1111import Data.Boolean
1212import Data.Function
@@ -14,16 +14,16 @@ import Data.Vinyl
1414import GHC.Exts
1515import Test.Hspec
1616
17−import Squeel.PostgreSQL.Query
17+import Squeel.PostgreSQL.Statement
1818import Squeel.PostgreSQL.Schema
1919
2020spec :: Spec
2121spec = do
2222 let
23− query `shouldRenderAs` str = renderQuery query `shouldBe` str
23+ query `shouldRenderAs` str = renderStatement query `shouldBe` str
2424 it "correctly renders a simple SELECT query" $ do
2525 let
26− statement :: Query '[] Tables Tables SumAndCol1
26+ statement :: Statement '[] Tables Tables SumAndCol1
2727 statement = select $
2828 ((#col1 + #col2) `As` #sum :& #col1 :& RNil)
2929 `from` (#table1 & where_ true)
@@ -31,7 +31,7 @@ spec = do
3131 "SELECT (col1 + col2) AS sum, col1 AS col1 FROM table1 WHERE TRUE;"
3232 it "combines WHEREs using AND" $ do
3333 let
34− statement :: Query '[] Tables Tables SumAndCol1
34+ statement :: Statement '[] Tables Tables SumAndCol1
3535 statement = select $
3636 ((#col1 + #col2) `As` #sum :& #col1 :& RNil)
3737 `from` (#table1 & where_ true & where_ false)
@@ -40,45 +40,45 @@ spec = do
4040 it "performs sub SELECTs" $ do
4141 let
4242 selection = ((#col1 + #col2) `As` #sum :& #col1 :& RNil) `from` #table1
43− statement :: Query '[] Tables Tables SumAndCol1
43+ statement :: Statement '[] Tables Tables SumAndCol1
4444 statement = select $ starFrom (subselect (selection `As` #sub))
4545 statement `shouldRenderAs`
4646 "SELECT * FROM SELECT (col1 + col2) AS sum, col1 AS col1 FROM table1 AS sub;"
4747 it "does LIMIT clauses" $ do
4848 let
49− statement :: Query '[] Tables Tables Columns
49+ statement :: Statement '[] Tables Tables Columns
5050 statement = select $ starFrom (#table1 & limit 1)
5151 statement `shouldRenderAs` "SELECT * FROM table1 LIMIT 1;"
5252 it "should use the minimum of given LIMITs" $ do
5353 let
54− statement :: Query '[] Tables Tables Columns
54+ statement :: Statement '[] Tables Tables Columns
5555 statement = select $ starFrom (#table1 & limit 1 & limit 2)
5656 statement `shouldRenderAs`
5757 "SELECT * FROM table1 LIMIT CASE WHEN (1 <= 2) THEN 1 ELSE 2 END;"
5858 it "should render parameters using $ signs" $ do
5959 let
60− statement :: Query '[ 'PGInt8] Tables Tables Columns
60+ statement :: Statement '[ 'PGInt8] Tables Tables Columns
6161 statement = select $ starFrom (#table1 & limit param1)
6262 statement `shouldRenderAs` "SELECT * FROM table1 LIMIT $1;"
6363 it "does OFFSET clauses" $ do
6464 let
65− statement :: Query '[] Tables Tables Columns
65+ statement :: Statement '[] Tables Tables Columns
6666 statement = select $ starFrom (#table1 & offset 1)
6767 statement `shouldRenderAs` "SELECT * FROM table1 OFFSET 1;"
6868 it "should use the sum of given OFFSETs" $ do
6969 let
70− statement :: Query '[] Tables Tables Columns
70+ statement :: Statement '[] Tables Tables Columns
7171 statement = select $ starFrom (#table1 & offset 1 & offset 2)
7272 statement `shouldRenderAs` "SELECT * FROM table1 OFFSET (1 + 2);"
7373 it "correctly render simple INSERTs" $ do
7474 let
75− statement :: Query '[] Tables Tables '[]
75+ statement :: Statement '[] Tables Tables '[]
7676 statement = insertInto #table1 $ 2 `As` #col1 :& 4 `As` #col2 :& RNil
7777 statement `shouldRenderAs`
7878 "INSERT INTO table1 (col1, col2) VALUES (2, 4);"
7979 it "should be safe against SQL injection in literal text" $ do
8080 let
81− statement :: Query '[] StudentsTable StudentsTable '[]
81+ statement :: Statement '[] StudentsTable StudentsTable '[]
8282 statement = insertInto #students $
8383 "Robert'); DROP TABLE students;" `As` #name :& RNil
8484 statement `shouldRenderAs`
@@ -91,7 +91,7 @@ spec = do
9191 :& #shippers .&. #shipperVal `As` #shipperVal :& RNil
9292 it "should render CROSS JOINs" $ do
9393 let
94− statement :: Query '[] JoinTables JoinTables ValueColumns
94+ statement :: Statement '[] JoinTables JoinTables ValueColumns
9595 statement = select $ vals `from`
9696 (tables (#orders & crossJoin #customers & crossJoin #shippers))
9797 statement `shouldRenderAs`
@@ -111,7 +111,7 @@ spec = do
111111 (#orders .&. #customerID ==* #customers .&. #customerID)
112112 & innerJoin #shippers
113113 (#orders .&. #shipperID ==* #shippers .&. #shipperID)
114− selection :: Query '[] JoinTables JoinTables ValueColumns
114+ selection :: Statement '[] JoinTables JoinTables ValueColumns
115115 selection = select $ vals `from` innerJoins
116116 selection `shouldRenderAs`
117117 "SELECT\
@@ -125,13 +125,13 @@ spec = do
125125 \ ON (orders.shipperID = shippers.shipperID);"
126126 it "should render simple CREATE TABLE statements" $ do
127127 let
128− statement :: Query '[] '[] Tables '[]
128+ statement :: Statement '[] '[] Tables '[]
129129 statement = createTable #table1 (proxy# :: Proxy# Columns)
130130 statement `shouldRenderAs`
131131 "CREATE TABLE table1 (col1 int4, col2 int4);"
132132 it "should render DROP TABLE statements" $ do
133133 let
134− statement :: Query '[] Tables '[] '[]
134+ statement :: Statement '[] Tables '[] '[]
135135 statement = dropTable #table1
136136 statement `shouldRenderAs`
137137 "DROP TABLE table1;"