on dev help sign in
reorder type variables in Statement
commit85723d061dd7dd2e5d2beee0b446e4a7943d6e7f authorEitan Chatav <eitan.chatav@gmail.com> dateMon 26 Jun 2017, 13:41 (9 years ago) parent8571e21
4 files changed+34−34
squeel-postgresql/exe/Example.hs+1−1 squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+8−8 squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+10−10 squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+15−15
squeel-postgresql/exe/Example.hs+1−1
@@ -33,7 +33,7 @@ main = do
3333 &>>
3434 insertInto #table1 ( 3 `As` #col1 :& 4 `As` #col2 :& RNil )
3535 Just selectTable1Result <- flip pqExecParams RNil $
36− (select $ starFrom #table1 :: Statement '[] Tables Tables Columns)
36+ (select $ starFrom #table1 :: Statement '[] Columns Tables Tables)
3737 Just (Right value00) <- getvalue selectTable1Result (RowNumber 0) colNum0
3838 Just (Right value01) <- getvalue selectTable1Result (RowNumber 0) colNum1
3939 Just (Right value10) <- getvalue selectTable1Result (RowNumber 1) colNum0
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+8−8
@@ -66,24 +66,24 @@ class MonadPQ pq where
6666
6767 pqExec
6868 :: MonadBase IO io
69− => Statement '[] db0 db1 '[]
69+ => Statement '[] '[] db0 db1
7070 -> pq db0 db1 io (Maybe (Result '[]))
7171
7272 pqExecParams
7373 :: (MonadBase IO io, ToOids ps, ToValues xs ps)
74− => Statement ps db0 db1 ys
74+ => Statement ps ys db0 db1
7575 -> Rec Identity xs
7676 -> pq db0 db1 io (Maybe (Result ys))
7777
7878 pqPrepare
7979 :: (MonadBase IO io, ToOids ps)
8080 => ByteString
81− -> Statement ps db0 db1 xs
82− -> pq db0 db1 io (Maybe (Result []), PreparedStatement ps db0 db1 xs)
81+ -> Statement ps xs db0 db1
82+ -> pq db0 db1 io (Maybe (Result []), PreparedStatement ps xs db0 db1)
8383
8484 pqExecPrepared
8585 :: (MonadBase IO io, ToValues xs ps)
86− => PreparedStatement ps db0 db1 ys
86+ => PreparedStatement ps ys db0 db1
8787 -> Rec Identity xs
8888 -> pq db0 db1 io (Maybe (Result ys))
8989
@@ -102,7 +102,7 @@ instance MonadPQ PQ where
102102 result <- liftBase $ LibPQ.exec conn q
103103 return (Result <$> result, Connection conn)
104104
105− pqExecParams (UnsafeStatement q :: Statement ps db0 db1 ys) params =
105+ pqExecParams (UnsafeStatement q :: Statement ps ys db0 db1) params =
106106 PQ $ \ (Connection conn) -> do
107107 let
108108 params' =
@@ -115,7 +115,7 @@ instance MonadPQ PQ where
115115 result <- liftBase $ LibPQ.execParams conn q params' LibPQ.Binary
116116 return (Result <$> result, Connection conn)
117117
118− pqPrepare statementName (UnsafeStatement q :: Statement ps db0 db1 ys) =
118+ pqPrepare statementName (UnsafeStatement q :: Statement ps ys db0 db1) =
119119 PQ $ \ (Connection conn) -> do
120120 result <- liftBase $
121121 LibPQ.prepare conn statementName q (Just (toOids (proxy# :: Proxy# ps)))
@@ -124,7 +124,7 @@ instance MonadPQ PQ where
124124 , UnsafePreparedStatement statementName
125125 ) , Connection conn )
126126
127− pqExecPrepared (q :: PreparedStatement ps db0 db1 ys) params =
127+ pqExecPrepared (q :: PreparedStatement ps ys db0 db1) params =
128128 PQ $ \ (Connection conn) -> do
129129 let
130130 params' =
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+10−10
@@ -372,28 +372,28 @@ list `from` tabs = UnsafeSelection $
372372
373373newtype Statement
374374 (params :: [NullityType])
375+ (columns :: [(Symbol,NullityType)])
375376 (schema0 :: [(Symbol,[(Symbol,NullityType)])])
376377 (schema1 :: [(Symbol,[(Symbol,NullityType)])])
377− (columns :: [(Symbol,NullityType)])
378378 = UnsafeStatement { renderStatement :: ByteString }
379379
380380(&>>)
381− :: Statement '[] schema0 schema1 '[]
382− -> Statement '[] schema1 schema2 results
383− -> Statement '[] schema0 schema2 results
381+ :: Statement '[] '[] schema0 schema1
382+ -> Statement '[] '[] schema1 schema2
383+ -> Statement '[] '[] schema0 schema2
384384statement1 &>> statement2 = UnsafeStatement $
385385 renderStatement statement1 <> " " <> renderStatement statement2
386386
387387newtype PreparedStatement
388388 (params :: [NullityType])
389+ (columns :: [(Symbol,NullityType)])
389390 (schema0 :: [(Symbol,[(Symbol,NullityType)])])
390391 (schema1 :: [(Symbol,[(Symbol,NullityType)])])
391− (columns :: [(Symbol,NullityType)])
392392 = UnsafePreparedStatement { renderPreparedStatement :: ByteString }
393393
394394select
395395 :: Selection params schema columns
396− -> Statement params schema schema columns
396+ -> Statement params columns schema schema
397397select = UnsafeStatement . ("SELECT " <>) . (<> ";") . renderSelection
398398
399399subselect
@@ -408,7 +408,7 @@ insertInto
408408 :: HasTable table schema columns
409409 => Alias table
410410 -> Rec (Aliased (Expression params '[])) columns
411− -> Statement params schema schema '[]
411+ -> Statement params '[] schema schema
412412insertInto (Alias table) expressions = UnsafeStatement $ "INSERT INTO "
413413 <> fromString (symbolVal' table)
414414 <> " (" <> ByteString.intercalate ", " aliases
@@ -427,7 +427,7 @@ createTable
427427 :: (KnownSymbol table, KnownColumns columns)
428428 => Alias table
429429 -> Proxy# columns
430− -> Statement '[] schema ((table ::: columns) ': schema) '[]
430+ -> Statement '[] '[] schema ((table ::: columns) ': schema)
431431createTable (Alias table) columns = UnsafeStatement $ mconcat
432432 [ "CREATE TABLE "
433433 , fromString $ symbolVal' table
@@ -438,7 +438,7 @@ createTable (Alias table) columns = UnsafeStatement $ mconcat
438438
439439class KnownSymbol table => DropTable table schema0 schema1
440440 | table schema0 -> schema1 where
441− dropTable :: Alias table -> Statement '[] schema0 schema1 '[]
441+ dropTable :: Alias table -> Statement '[] '[] schema0 schema1
442442 dropTable (Alias table) = UnsafeStatement $
443443 "DROP TABLE " <> fromString (symbolVal' table) <> ";"
444444instance {-# OVERLAPPING #-}
@@ -459,7 +459,7 @@ update
459459 => Alias table
460460 -> Rec (Aliased (Maybe `Compose` Expression params '[table ::: columns])) columns
461461 -> Expression params '[table ::: columns] ('NotNull 'PGBool)
462− -> Statement params schema schema '[]
462+ -> Statement params '[] schema schema
463463update (Alias table) columns where' = UnsafeStatement $ mconcat
464464 [ "UPDATE "
465465 , fromString $ symbolVal' table
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+15−15
@@ -23,7 +23,7 @@ spec = do
2323 query `shouldRenderAs` str = renderStatement query `shouldBe` str
2424 it "correctly renders a simple SELECT query" $ do
2525 let
26− statement :: Statement '[] Tables Tables SumAndCol1
26+ statement :: Statement '[] SumAndCol1 Tables Tables
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 AS table1 WHERE TRUE;"
3232 it "combines WHEREs using AND" $ do
3333 let
34− statement :: Statement '[] Tables Tables SumAndCol1
34+ statement :: Statement '[] SumAndCol1 Tables Tables
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 :: Statement '[] Tables Tables SumAndCol1
43+ statement :: Statement '[] SumAndCol1 Tables Tables
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 table1 AS sub;"
4747 it "does LIMIT clauses" $ do
4848 let
49− statement :: Statement '[] Tables Tables Columns
49+ statement :: Statement '[] Columns Tables Tables
5050 statement = select $ starFrom (#table1 & limit 1)
5151 statement `shouldRenderAs` "SELECT * FROM table1 AS table1 LIMIT 1;"
5252 it "should use the minimum of given LIMITs" $ do
5353 let
54− statement :: Statement '[] Tables Tables Columns
54+ statement :: Statement '[] Columns Tables Tables
5555 statement = select $ starFrom (#table1 & limit 1 & limit 2)
5656 statement `shouldRenderAs`
5757 "SELECT * FROM table1 AS table1 LIMIT CASE WHEN (1 <= 2) THEN 1 ELSE 2 END;"
5858 it "should render parameters using $ signs" $ do
5959 let
60− statement :: Statement '[ 'NotNull 'PGInt8] Tables Tables Columns
60+ statement :: Statement '[ 'NotNull 'PGInt8] Columns Tables Tables
6161 statement = select $ starFrom (#table1 & limit param1)
6262 statement `shouldRenderAs` "SELECT * FROM table1 AS table1 LIMIT $1;"
6363 it "does OFFSET clauses" $ do
6464 let
65− statement :: Statement '[] Tables Tables Columns
65+ statement :: Statement '[] Columns Tables Tables
6666 statement = select $ starFrom (#table1 & offset 1)
6767 statement `shouldRenderAs` "SELECT * FROM table1 AS table1 OFFSET 1;"
6868 it "should use the sum of given OFFSETs" $ do
6969 let
70− statement :: Statement '[] Tables Tables Columns
70+ statement :: Statement '[] Columns Tables Tables
7171 statement = select $ starFrom (#table1 & offset 1 & offset 2)
7272 statement `shouldRenderAs` "SELECT * FROM table1 AS table1 OFFSET (1 + 2);"
7373 it "correctly render simple INSERTs" $ do
7474 let
75− statement :: Statement '[] 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 :: Statement '[] 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 :: Statement '[] JoinTables JoinTables ValueColumns
94+ statement :: Statement '[] ValueColumns JoinTables JoinTables
9595 statement = select $ vals `from`
9696 (join (#orders & Cross #customers & Cross #shippers))
9797 statement `shouldRenderAs`
@@ -111,7 +111,7 @@ spec = do
111111 (#orders &. #customerID ==* #customers &. #customerID)
112112 & Inner #shippers
113113 (#orders &. #shipperID ==* #shippers &. #shipperID)
114− selection :: Statement '[] JoinTables JoinTables ValueColumns
114+ selection :: Statement '[] ValueColumns JoinTables JoinTables
115115 selection = select $ vals `from` innerJoins
116116 selection `shouldRenderAs`
117117 "SELECT\
@@ -125,7 +125,7 @@ spec = do
125125 \ ON (orders.shipperID = shippers.shipperID);"
126126 it "should render self JOINs" $ do
127127 let
128− statement :: Statement '[] JoinTables JoinTables OrderColumns
128+ statement :: Statement '[] OrderColumns JoinTables JoinTables
129129 statement = select $ #orders1 `dotStarFrom`
130130 (join (Table (#orders `As` #orders1)
131131 & Cross (#orders `As` #orders2)))
@@ -135,13 +135,13 @@ spec = do
135135 \ CROSS JOIN orders AS orders2;"
136136 it "should render simple CREATE TABLE statements" $ do
137137 let
138− statement :: Statement '[] '[] Tables '[]
138+ statement :: Statement '[] '[] '[] Tables
139139 statement = createTable #table1 (proxy# :: Proxy# Columns)
140140 statement `shouldRenderAs`
141141 "CREATE TABLE table1 (col1 int4 NOT NULL, col2 int4 NOT NULL);"
142142 it "should render DROP TABLE statements" $ do
143143 let
144− statement :: Statement '[] Tables '[] '[]
144+ statement :: Statement '[] '[] Tables '[]
145145 statement = dropTable #table1
146146 statement `shouldRenderAs` "DROP TABLE table1;"
147147