on dev help sign in
renaming
993b787Eitan Chatav
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+6−6
@@ -78,12 +78,12 @@ class AtkeyPQ pq where
78
78
79 pqExec
79 pqExec
80 :: MonadBase IO io
80 :: MonadBase IO io
81− => DataDefinition db0 db1
81+ => Definition db0 db1
82 -> pq db0 db1 io (Maybe (Result '[]))
82 -> pq db0 db1 io (Maybe (Result '[]))
83
83
84 pqThenExec
84 pqThenExec
85 :: MonadBase IO io
85 :: MonadBase IO io
86− => DataDefinition db1 db2
86+ => Definition db1 db2
87 -> pq db0 db1 io x
87 -> pq db0 db1 io x
88 -> pq db0 db2 io (Maybe (Result '[]))
88 -> pq db0 db2 io (Maybe (Result '[]))
89 pqThenExec = pqThen . pqExec
89 pqThenExec = pqThen . pqExec
@@ -92,12 +92,12 @@ class MonadPQ db m | m -> db where
92
92
93 pqExecParams
93 pqExecParams
94 :: (ToOids ps, AllZip HasEncoding ps xs)
94 :: (ToOids ps, AllZip HasEncoding ps xs)
95− => DataManipulation db ps ys
95+ => Manipulation db ps ys
96 -> NP I xs
96 -> NP I xs
97 -> m (Maybe (Result ys))
97 -> m (Maybe (Result ys))
98
98
99 pqExecNil
99 pqExecNil
100− :: DataManipulation db '[] ys
100+ :: Manipulation db '[] ys
101 -> m (Maybe (Result ys))
101 -> m (Maybe (Result ys))
102 pqExecNil statement = pqExecParams statement Nil
102 pqExecNil statement = pqExecParams statement Nil
103
103
@@ -112,13 +112,13 @@ instance AtkeyPQ PQ where
112 (x', conn') <- x conn
112 (x', conn') <- x conn
113 runPQ (f x') conn'
113 runPQ (f x') conn'
114
114
115− pqExec (UnsafeDataDefinition q) = PQ $ \ (Connection conn) -> do
115+ pqExec (UnsafeDefinition q) = PQ $ \ (Connection conn) -> do
116 result <- liftBase $ LibPQ.exec conn q
116 result <- liftBase $ LibPQ.exec conn q
117 return (Result <$> result, Connection conn)
117 return (Result <$> result, Connection conn)
118
118
119instance MonadBase IO io => MonadPQ db (PQ db db io) where
119instance MonadBase IO io => MonadPQ db (PQ db db io) where
120
120
121− pqExecParams (UnsafeDataManipulation q :: DataManipulation db ps ys) params =
121+ pqExecParams (UnsafeManipulation q :: Manipulation db ps ys) params =
122 PQ $ \ (Connection conn) -> do
122 PQ $ \ (Connection conn) -> do
123 let
123 let
124 paramValues = encodings (Proxy :: Proxy ps) params
124 paramValues = encodings (Proxy :: Proxy ps) params
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+32−32
@@ -640,21 +640,21 @@ instance PGTyped 'PGJsonb where pgtype = jsonb
640statements
640statements
641-----------------------------------------}
641-----------------------------------------}
642
642
643−newtype DataDefinition
643+newtype Definition
644 (schema0 :: [(Symbol,[(Symbol,ColumnType)])])
644 (schema0 :: [(Symbol,[(Symbol,ColumnType)])])
645 (schema1 :: [(Symbol,[(Symbol,ColumnType)])])
645 (schema1 :: [(Symbol,[(Symbol,ColumnType)])])
646− = UnsafeDataDefinition { renderDataDefinition :: ByteString }
646+ = UnsafeDefinition { renderDefinition :: ByteString }
647
647
648−instance Category DataDefinition where
648+instance Category Definition where
649− id = UnsafeDataDefinition ";"
649+ id = UnsafeDefinition ";"
650− dd1 . dd0 = UnsafeDataDefinition $
650+ dd1 . dd0 = UnsafeDefinition $
651− renderDataDefinition dd0 <> " " <> renderDataDefinition dd1
651+ renderDefinition dd0 <> " " <> renderDefinition dd1
652
652
653−newtype DataManipulation
653+newtype Manipulation
654 (schema :: [(Symbol,[(Symbol,ColumnType)])])
654 (schema :: [(Symbol,[(Symbol,ColumnType)])])
655 (params :: [ColumnType])
655 (params :: [ColumnType])
656 (columns :: [(Symbol,ColumnType)])
656 (columns :: [(Symbol,ColumnType)])
657− = UnsafeDataManipulation { renderDataManipulation :: ByteString }
657+ = UnsafeManipulation { renderManipulation :: ByteString }
658
658
659newtype Query
659newtype Query
660 (schema :: [(Symbol,[(Symbol,ColumnType)])])
660 (schema :: [(Symbol,[(Symbol,ColumnType)])])
@@ -664,8 +664,8 @@ newtype Query
664
664
665query
665query
666 :: Query schema params columns
666 :: Query schema params columns
667− -> DataManipulation schema params columns
667+ -> Manipulation schema params columns
668−query q = UnsafeDataManipulation $ renderQuery q <> ";"
668+query q = UnsafeManipulation $ renderQuery q <> ";"
669
669
670union, unionAll, intersect, intersectAll, except, exceptAll
670union, unionAll, intersect, intersectAll, except, exceptAll
671 :: Query schema params columns
671 :: Query schema params columns
@@ -723,8 +723,8 @@ createTable
723 :: (KnownSymbol table, SListI columns)
723 :: (KnownSymbol table, SListI columns)
724 => Alias table
724 => Alias table
725 -> NP (Aliased TypeExpression) columns
725 -> NP (Aliased TypeExpression) columns
726− -> DataDefinition schema (Create table columns schema)
726+ -> Definition schema (Create table columns schema)
727−createTable table columns = UnsafeDataDefinition $ mconcat
727+createTable table columns = UnsafeDefinition $ mconcat
728 [ "CREATE TABLE "
728 [ "CREATE TABLE "
729 , renderAlias table
729 , renderAlias table
730 , " ("
730 , " ("
@@ -744,8 +744,8 @@ DROP statements
744dropTable
744dropTable
745 :: KnownSymbol table
745 :: KnownSymbol table
746 => Alias table
746 => Alias table
747− -> DataDefinition schema (Drop table schema)
747+ -> Definition schema (Drop table schema)
748−dropTable table = UnsafeDataDefinition $ "DROP TABLE " <> renderAlias table <> ";"
748+dropTable table = UnsafeDefinition $ "DROP TABLE " <> renderAlias table <> ";"
749
749
750{-----------------------------------------
750{-----------------------------------------
751ALTER statements
751ALTER statements
@@ -755,8 +755,8 @@ alterTable
755 :: HasTable table schema columns0
755 :: HasTable table schema columns0
756 => Alias table
756 => Alias table
757 -> AlterTable columns0 columns1
757 -> AlterTable columns0 columns1
758− -> DataDefinition schema (Alter table schema columns1)
758+ -> Definition schema (Alter table schema columns1)
759−alterTable table alteration = UnsafeDataDefinition $
759+alterTable table alteration = UnsafeDefinition $
760 "ALTER TABLE "
760 "ALTER TABLE "
761 <> renderAlias table
761 <> renderAlias table
762 <> " "
762 <> " "
@@ -767,8 +767,8 @@ alterTableRename
767 :: (KnownSymbol table0, KnownSymbol table1)
767 :: (KnownSymbol table0, KnownSymbol table1)
768 => Alias table0
768 => Alias table0
769 -> Alias table1
769 -> Alias table1
770− -> DataDefinition schema (Rename table0 table1 schema)
770+ -> Definition schema (Rename table0 table1 schema)
771−alterTableRename table0 table1 = UnsafeDataDefinition $
771+alterTableRename table0 table1 = UnsafeDefinition $
772 "ALTER TABLE "
772 "ALTER TABLE "
773 <> renderAlias table0
773 <> renderAlias table0
774 <> " RENAME TO "
774 <> " RENAME TO "
@@ -861,8 +861,8 @@ insertInto
861 :: (SListI columns, HasTable table schema columns)
861 :: (SListI columns, HasTable table schema columns)
862 => Alias table
862 => Alias table
863 -> NP (Aliased (Expression params '[])) columns
863 -> NP (Aliased (Expression params '[])) columns
864− -> DataManipulation schema params '[]
864+ -> Manipulation schema params '[]
865−insertInto table expressions = UnsafeDataManipulation $ "INSERT INTO "
865+insertInto table expressions = UnsafeManipulation $ "INSERT INTO "
866 <> renderAlias table
866 <> renderAlias table
867 <> " (" <> ByteString.intercalate ", " aliases
867 <> " (" <> ByteString.intercalate ", " aliases
868 <> ") VALUES ("
868 <> ") VALUES ("
@@ -881,9 +881,9 @@ insertIntoReturning
881 => Alias table
881 => Alias table
882 -> NP (Aliased (Expression params '[])) columns
882 -> NP (Aliased (Expression params '[])) columns
883 -> NP (Aliased (Expression params '[table ::: columns])) results
883 -> NP (Aliased (Expression params '[table ::: columns])) results
884− -> DataManipulation schema params results
884+ -> Manipulation schema params results
885insertIntoReturning table inserts results
885insertIntoReturning table inserts results
886− = UnsafeDataManipulation . mconcat $
886+ = UnsafeManipulation . mconcat $
887 [ "INSERT INTO "
887 [ "INSERT INTO "
888 , renderAlias table
888 , renderAlias table
889 , " (" <> ByteString.intercalate ", " aliases
889 , " (" <> ByteString.intercalate ", " aliases
@@ -929,8 +929,8 @@ update
929 => Alias table
929 => Alias table
930 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
930 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
931 -> Condition params '[table ::: columns]
931 -> Condition params '[table ::: columns]
932− -> DataManipulation schema params '[]
932+ -> Manipulation schema params '[]
933−update table columns wh = UnsafeDataManipulation $ mconcat
933+update table columns wh = UnsafeManipulation $ mconcat
934 [ "UPDATE "
934 [ "UPDATE "
935 , renderAlias table
935 , renderAlias table
936 , " SET "
936 , " SET "
@@ -945,8 +945,8 @@ updateReturning
945 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
945 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
946 -> Condition params '[table ::: columns]
946 -> Condition params '[table ::: columns]
947 -> NP (Aliased (Expression params '[table ::: columns])) results
947 -> NP (Aliased (Expression params '[table ::: columns])) results
948− -> DataManipulation schema params results
948+ -> Manipulation schema params results
949−updateReturning table updates wh results = UnsafeDataManipulation $ mconcat
949+updateReturning table updates wh results = UnsafeManipulation $ mconcat
950 [ "UPDATE "
950 [ "UPDATE "
951 , renderAlias table
951 , renderAlias table
952 , " SET "
952 , " SET "
@@ -968,8 +968,8 @@ upsertInto
968 -> NP (Aliased (Expression params '[])) columns
968 -> NP (Aliased (Expression params '[])) columns
969 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
969 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
970 -> Condition params '[table ::: columns]
970 -> Condition params '[table ::: columns]
971− -> DataManipulation schema params '[]
971+ -> Manipulation schema params '[]
972−upsertInto table inserts updates wh = UnsafeDataManipulation . mconcat $
972+upsertInto table inserts updates wh = UnsafeManipulation . mconcat $
973 [ "INSERT INTO "
973 [ "INSERT INTO "
974 , renderAlias table
974 , renderAlias table
975 , " (" <> ByteString.intercalate ", " aliases
975 , " (" <> ByteString.intercalate ", " aliases
@@ -996,9 +996,9 @@ upsertIntoReturning
996 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
996 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
997 -> Condition params '[table ::: columns]
997 -> Condition params '[table ::: columns]
998 -> NP (Aliased (Expression params '[table ::: columns])) results
998 -> NP (Aliased (Expression params '[table ::: columns])) results
999− -> DataManipulation schema params results
999+ -> Manipulation schema params results
1000upsertIntoReturning table inserts updates wh results =
1000upsertIntoReturning table inserts updates wh results =
1001− UnsafeDataManipulation . mconcat $
1001+ UnsafeManipulation . mconcat $
1002 [ "INSERT INTO "
1002 [ "INSERT INTO "
1003 , renderAlias table
1003 , renderAlias table
1004 , " (" <> ByteString.intercalate ", " aliases
1004 , " (" <> ByteString.intercalate ", " aliases
@@ -1032,8 +1032,8 @@ deleteFrom
1032 :: HasTable table schema columns
1032 :: HasTable table schema columns
1033 => Alias table
1033 => Alias table
1034 -> Condition params '[table ::: columns]
1034 -> Condition params '[table ::: columns]
1035− -> DataManipulation schema params '[]
1035+ -> Manipulation schema params '[]
1036−deleteFrom table wh = UnsafeDataManipulation $ mconcat
1036+deleteFrom table wh = UnsafeManipulation $ mconcat
1037 [ "DELETE FROM "
1037 [ "DELETE FROM "
1038 , renderAlias table
1038 , renderAlias table
1039 , " WHERE ", renderExpression wh, ";"
1039 , " WHERE ", renderExpression wh, ";"
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+11−11
@@ -20,9 +20,9 @@ spec = do
20 let
20 let
21 qry `queryRenders` str = query qry `manipulationRenders` str
21 qry `queryRenders` str = query qry `manipulationRenders` str
22 definition `definitionRenders` str =
22 definition `definitionRenders` str =
23− renderDataDefinition definition `shouldBe` str
23+ renderDefinition definition `shouldBe` str
24 manipulation `manipulationRenders` str =
24 manipulation `manipulationRenders` str =
25− renderDataManipulation manipulation `shouldBe` str
25+ renderManipulation manipulation `shouldBe` str
26 it "correctly renders a simple SELECT query" $ do
26 it "correctly renders a simple SELECT query" $ do
27 let
27 let
28 statement :: Query Tables '[] SumAndCol1
28 statement :: Query Tables '[] SumAndCol1
@@ -81,13 +81,13 @@ spec = do
81 statement `queryRenders` "SELECT * FROM table1 AS table1 OFFSET 3;"
81 statement `queryRenders` "SELECT * FROM table1 AS table1 OFFSET 3;"
82 it "correctly renders simple INSERTs" $ do
82 it "correctly renders simple INSERTs" $ do
83 let
83 let
84− statement :: DataManipulation Tables '[] '[]
84+ statement :: Manipulation Tables '[] '[]
85 statement = insertInto #table1 $ 2 `As` #col1 :* 4 `As` #col2 :* Nil
85 statement = insertInto #table1 $ 2 `As` #col1 :* 4 `As` #col2 :* Nil
86 statement `manipulationRenders`
86 statement `manipulationRenders`
87 "INSERT INTO table1 (col1, col2) VALUES (2, 4);"
87 "INSERT INTO table1 (col1, col2) VALUES (2, 4);"
88 it "correctly renders returning INSERTs" $ do
88 it "correctly renders returning INSERTs" $ do
89 let
89 let
90− statement :: DataManipulation Tables '[] SumAndCol1
90+ statement :: Manipulation Tables '[] SumAndCol1
91 statement = insertIntoReturning #table1
91 statement = insertIntoReturning #table1
92 (2 `As` #col1 :* 4 `As` #col2 :* Nil)
92 (2 `As` #col1 :* 4 `As` #col2 :* Nil)
93 ((#col1 + #col2) `As` #sum :* #col1 `As` #col1 :* Nil)
93 ((#col1 + #col2) `As` #sum :* #col1 `As` #col1 :* Nil)
@@ -95,7 +95,7 @@ spec = do
95 "INSERT INTO table1 (col1, col2) VALUES (2, 4) RETURNING (col1 + col2) AS sum, col1 AS col1;"
95 "INSERT INTO table1 (col1, col2) VALUES (2, 4) RETURNING (col1 + col2) AS sum, col1 AS col1;"
96 it "correctly renders simple UPDATEs" $ do
96 it "correctly renders simple UPDATEs" $ do
97 let
97 let
98− statement :: DataManipulation Tables '[] '[]
98+ statement :: Manipulation Tables '[] '[]
99 statement = update #table1
99 statement = update #table1
100 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
100 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
101 (#col1 /=* #col2)
101 (#col1 /=* #col2)
@@ -103,7 +103,7 @@ spec = do
103 "UPDATE table1 SET col1 = 2 WHERE (col1 <> col2);"
103 "UPDATE table1 SET col1 = 2 WHERE (col1 <> col2);"
104 it "correctly renders returning UPDATEs" $ do
104 it "correctly renders returning UPDATEs" $ do
105 let
105 let
106− statement :: DataManipulation Tables '[] SumAndCol1
106+ statement :: Manipulation Tables '[] SumAndCol1
107 statement = updateReturning #table1
107 statement = updateReturning #table1
108 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
108 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
109 (#col1 /=* #col2)
109 (#col1 /=* #col2)
@@ -112,7 +112,7 @@ spec = do
112 "UPDATE table1 SET col1 = 2 WHERE (col1 <> col2) RETURNING (col1 + col2) AS sum, col1 AS col1;"
112 "UPDATE table1 SET col1 = 2 WHERE (col1 <> col2) RETURNING (col1 + col2) AS sum, col1 AS col1;"
113 it "correctly renders upsert INSERTs" $ do
113 it "correctly renders upsert INSERTs" $ do
114 let
114 let
115− statement :: DataManipulation Tables '[] '[]
115+ statement :: Manipulation Tables '[] '[]
116 statement = upsertInto #table1
116 statement = upsertInto #table1
117 (2 `As` #col1 :* 4 `As` #col2 :* Nil)
117 (2 `As` #col1 :* 4 `As` #col2 :* Nil)
118 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
118 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
@@ -121,7 +121,7 @@ spec = do
121 "INSERT INTO table1 (col1, col2) VALUES (2, 4) ON CONFLICT UPDATE table1 SET col1 = 2 WHERE (col1 <> col2);"
121 "INSERT INTO table1 (col1, col2) VALUES (2, 4) ON CONFLICT UPDATE table1 SET col1 = 2 WHERE (col1 <> col2);"
122 it "correctly renders returning upsert INSERTs" $ do
122 it "correctly renders returning upsert INSERTs" $ do
123 let
123 let
124− statement :: DataManipulation Tables '[] SumAndCol1
124+ statement :: Manipulation Tables '[] SumAndCol1
125 statement = upsertIntoReturning #table1
125 statement = upsertIntoReturning #table1
126 (2 `As` #col1 :* 4 `As` #col2 :* Nil)
126 (2 `As` #col1 :* 4 `As` #col2 :* Nil)
127 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
127 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
@@ -131,13 +131,13 @@ spec = do
131 "INSERT INTO table1 (col1, col2) VALUES (2, 4) ON CONFLICT UPDATE table1 SET col1 = 2 WHERE (col1 <> col2) RETURNING (col1 + col2) AS sum, col1 AS col1;"
131 "INSERT INTO table1 (col1, col2) VALUES (2, 4) ON CONFLICT UPDATE table1 SET col1 = 2 WHERE (col1 <> col2) RETURNING (col1 + col2) AS sum, col1 AS col1;"
132 it "correctly renders DELETEs" $ do
132 it "correctly renders DELETEs" $ do
133 let
133 let
134− statement :: DataManipulation Tables '[] '[]
134+ statement :: Manipulation Tables '[] '[]
135 statement = deleteFrom #table1 (#col1 ==* #col2)
135 statement = deleteFrom #table1 (#col1 ==* #col2)
136 statement `manipulationRenders`
136 statement `manipulationRenders`
137 "DELETE FROM table1 WHERE (col1 = col2);"
137 "DELETE FROM table1 WHERE (col1 = col2);"
138 it "should be safe against SQL injection in literal text" $ do
138 it "should be safe against SQL injection in literal text" $ do
139 let
139 let
140− statement :: DataManipulation StudentsTable '[] '[]
140+ statement :: Manipulation StudentsTable '[] '[]
141 statement = insertInto #students $
141 statement = insertInto #students $
142 "Robert'); DROP TABLE students;" `As` #name :* Nil
142 "Robert'); DROP TABLE students;" `As` #name :* Nil
143 statement `manipulationRenders`
143 statement `manipulationRenders`
@@ -209,7 +209,7 @@ spec = do
209 "CREATE TABLE table2 (col1 serial, col2 text, col3 int8 NOT NULL DEFAULT 8);"
209 "CREATE TABLE table2 (col1 serial, col2 text, col3 int8 NOT NULL DEFAULT 8);"
210 it "should render DROP TABLE statements" $ do
210 it "should render DROP TABLE statements" $ do
211 let
211 let
212− statement :: DataDefinition Tables '[]
212+ statement :: Definition Tables '[]
213 statement = dropTable #table1
213 statement = dropTable #table1
214 statement `definitionRenders` "DROP TABLE table1;"
214 statement `definitionRenders` "DROP TABLE table1;"
215
215