on dev help sign in
renaming
commit993b787e12ca2e849c181a91ad8c34600f3eddde authorEitan Chatav <eitan.chatav@gmail.com> dateMon 7 Aug 2017, 10:25 (9 years ago) parentdcb0870
3 files changed+49−49
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+6−6 squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+32−32 squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+11−11
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+6−6
@@ -78,12 +78,12 @@ class AtkeyPQ pq where
7878
7979 pqExec
8080 :: MonadBase IO io
81− => DataDefinition db0 db1
81+ => Definition db0 db1
8282 -> pq db0 db1 io (Maybe (Result '[]))
8383
8484 pqThenExec
8585 :: MonadBase IO io
86− => DataDefinition db1 db2
86+ => Definition db1 db2
8787 -> pq db0 db1 io x
8888 -> pq db0 db2 io (Maybe (Result '[]))
8989 pqThenExec = pqThen . pqExec
@@ -92,12 +92,12 @@ class MonadPQ db m | m -> db where
9292
9393 pqExecParams
9494 :: (ToOids ps, AllZip HasEncoding ps xs)
95− => DataManipulation db ps ys
95+ => Manipulation db ps ys
9696 -> NP I xs
9797 -> m (Maybe (Result ys))
9898
9999 pqExecNil
100− :: DataManipulation db '[] ys
100+ :: Manipulation db '[] ys
101101 -> m (Maybe (Result ys))
102102 pqExecNil statement = pqExecParams statement Nil
103103
@@ -112,13 +112,13 @@ instance AtkeyPQ PQ where
112112 (x', conn') <- x conn
113113 runPQ (f x') conn'
114114
115− pqExec (UnsafeDataDefinition q) = PQ $ \ (Connection conn) -> do
115+ pqExec (UnsafeDefinition q) = PQ $ \ (Connection conn) -> do
116116 result <- liftBase $ LibPQ.exec conn q
117117 return (Result <$> result, Connection conn)
118118
119119instance MonadBase IO io => MonadPQ db (PQ db db io) where
120120
121− pqExecParams (UnsafeDataManipulation q :: DataManipulation db ps ys) params =
121+ pqExecParams (UnsafeManipulation q :: Manipulation db ps ys) params =
122122 PQ $ \ (Connection conn) -> do
123123 let
124124 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
640640statements
641641-----------------------------------------}
642642
643−newtype DataDefinition
643+newtype Definition
644644 (schema0 :: [(Symbol,[(Symbol,ColumnType)])])
645645 (schema1 :: [(Symbol,[(Symbol,ColumnType)])])
646− = UnsafeDataDefinition { renderDataDefinition :: ByteString }
646+ = UnsafeDefinition { renderDefinition :: ByteString }
647647
648−instance Category DataDefinition where
649− id = UnsafeDataDefinition ";"
650− dd1 . dd0 = UnsafeDataDefinition $
651− renderDataDefinition dd0 <> " " <> renderDataDefinition dd1
648+instance Category Definition where
649+ id = UnsafeDefinition ";"
650+ dd1 . dd0 = UnsafeDefinition $
651+ renderDefinition dd0 <> " " <> renderDefinition dd1
652652
653−newtype DataManipulation
653+newtype Manipulation
654654 (schema :: [(Symbol,[(Symbol,ColumnType)])])
655655 (params :: [ColumnType])
656656 (columns :: [(Symbol,ColumnType)])
657− = UnsafeDataManipulation { renderDataManipulation :: ByteString }
657+ = UnsafeManipulation { renderManipulation :: ByteString }
658658
659659newtype Query
660660 (schema :: [(Symbol,[(Symbol,ColumnType)])])
@@ -664,8 +664,8 @@ newtype Query
664664
665665query
666666 :: Query schema params columns
667− -> DataManipulation schema params columns
668−query q = UnsafeDataManipulation $ renderQuery q <> ";"
667+ -> Manipulation schema params columns
668+query q = UnsafeManipulation $ renderQuery q <> ";"
669669
670670union, unionAll, intersect, intersectAll, except, exceptAll
671671 :: Query schema params columns
@@ -723,8 +723,8 @@ createTable
723723 :: (KnownSymbol table, SListI columns)
724724 => Alias table
725725 -> NP (Aliased TypeExpression) columns
726− -> DataDefinition schema (Create table columns schema)
727−createTable table columns = UnsafeDataDefinition $ mconcat
726+ -> Definition schema (Create table columns schema)
727+createTable table columns = UnsafeDefinition $ mconcat
728728 [ "CREATE TABLE "
729729 , renderAlias table
730730 , " ("
@@ -744,8 +744,8 @@ DROP statements
744744dropTable
745745 :: KnownSymbol table
746746 => Alias table
747− -> DataDefinition schema (Drop table schema)
748−dropTable table = UnsafeDataDefinition $ "DROP TABLE " <> renderAlias table <> ";"
747+ -> Definition schema (Drop table schema)
748+dropTable table = UnsafeDefinition $ "DROP TABLE " <> renderAlias table <> ";"
749749
750750{-----------------------------------------
751751ALTER statements
@@ -755,8 +755,8 @@ alterTable
755755 :: HasTable table schema columns0
756756 => Alias table
757757 -> AlterTable columns0 columns1
758− -> DataDefinition schema (Alter table schema columns1)
759−alterTable table alteration = UnsafeDataDefinition $
758+ -> Definition schema (Alter table schema columns1)
759+alterTable table alteration = UnsafeDefinition $
760760 "ALTER TABLE "
761761 <> renderAlias table
762762 <> " "
@@ -767,8 +767,8 @@ alterTableRename
767767 :: (KnownSymbol table0, KnownSymbol table1)
768768 => Alias table0
769769 -> Alias table1
770− -> DataDefinition schema (Rename table0 table1 schema)
771−alterTableRename table0 table1 = UnsafeDataDefinition $
770+ -> Definition schema (Rename table0 table1 schema)
771+alterTableRename table0 table1 = UnsafeDefinition $
772772 "ALTER TABLE "
773773 <> renderAlias table0
774774 <> " RENAME TO "
@@ -861,8 +861,8 @@ insertInto
861861 :: (SListI columns, HasTable table schema columns)
862862 => Alias table
863863 -> NP (Aliased (Expression params '[])) columns
864− -> DataManipulation schema params '[]
865−insertInto table expressions = UnsafeDataManipulation $ "INSERT INTO "
864+ -> Manipulation schema params '[]
865+insertInto table expressions = UnsafeManipulation $ "INSERT INTO "
866866 <> renderAlias table
867867 <> " (" <> ByteString.intercalate ", " aliases
868868 <> ") VALUES ("
@@ -881,9 +881,9 @@ insertIntoReturning
881881 => Alias table
882882 -> NP (Aliased (Expression params '[])) columns
883883 -> NP (Aliased (Expression params '[table ::: columns])) results
884− -> DataManipulation schema params results
884+ -> Manipulation schema params results
885885insertIntoReturning table inserts results
886− = UnsafeDataManipulation . mconcat $
886+ = UnsafeManipulation . mconcat $
887887 [ "INSERT INTO "
888888 , renderAlias table
889889 , " (" <> ByteString.intercalate ", " aliases
@@ -929,8 +929,8 @@ update
929929 => Alias table
930930 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
931931 -> Condition params '[table ::: columns]
932− -> DataManipulation schema params '[]
933−update table columns wh = UnsafeDataManipulation $ mconcat
932+ -> Manipulation schema params '[]
933+update table columns wh = UnsafeManipulation $ mconcat
934934 [ "UPDATE "
935935 , renderAlias table
936936 , " SET "
@@ -945,8 +945,8 @@ updateReturning
945945 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
946946 -> Condition params '[table ::: columns]
947947 -> NP (Aliased (Expression params '[table ::: columns])) results
948− -> DataManipulation schema params results
949−updateReturning table updates wh results = UnsafeDataManipulation $ mconcat
948+ -> Manipulation schema params results
949+updateReturning table updates wh results = UnsafeManipulation $ mconcat
950950 [ "UPDATE "
951951 , renderAlias table
952952 , " SET "
@@ -968,8 +968,8 @@ upsertInto
968968 -> NP (Aliased (Expression params '[])) columns
969969 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
970970 -> Condition params '[table ::: columns]
971− -> DataManipulation schema params '[]
972−upsertInto table inserts updates wh = UnsafeDataManipulation . mconcat $
971+ -> Manipulation schema params '[]
972+upsertInto table inserts updates wh = UnsafeManipulation . mconcat $
973973 [ "INSERT INTO "
974974 , renderAlias table
975975 , " (" <> ByteString.intercalate ", " aliases
@@ -996,9 +996,9 @@ upsertIntoReturning
996996 -> NP (Aliased (UpdateExpression params '[table ::: columns])) columns
997997 -> Condition params '[table ::: columns]
998998 -> NP (Aliased (Expression params '[table ::: columns])) results
999− -> DataManipulation schema params results
999+ -> Manipulation schema params results
10001000upsertIntoReturning table inserts updates wh results =
1001− UnsafeDataManipulation . mconcat $
1001+ UnsafeManipulation . mconcat $
10021002 [ "INSERT INTO "
10031003 , renderAlias table
10041004 , " (" <> ByteString.intercalate ", " aliases
@@ -1032,8 +1032,8 @@ deleteFrom
10321032 :: HasTable table schema columns
10331033 => Alias table
10341034 -> Condition params '[table ::: columns]
1035− -> DataManipulation schema params '[]
1036−deleteFrom table wh = UnsafeDataManipulation $ mconcat
1035+ -> Manipulation schema params '[]
1036+deleteFrom table wh = UnsafeManipulation $ mconcat
10371037 [ "DELETE FROM "
10381038 , renderAlias table
10391039 , " WHERE ", renderExpression wh, ";"
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+11−11
@@ -20,9 +20,9 @@ spec = do
2020 let
2121 qry `queryRenders` str = query qry `manipulationRenders` str
2222 definition `definitionRenders` str =
23− renderDataDefinition definition `shouldBe` str
23+ renderDefinition definition `shouldBe` str
2424 manipulation `manipulationRenders` str =
25− renderDataManipulation manipulation `shouldBe` str
25+ renderManipulation manipulation `shouldBe` str
2626 it "correctly renders a simple SELECT query" $ do
2727 let
2828 statement :: Query Tables '[] SumAndCol1
@@ -81,13 +81,13 @@ spec = do
8181 statement `queryRenders` "SELECT * FROM table1 AS table1 OFFSET 3;"
8282 it "correctly renders simple INSERTs" $ do
8383 let
84− statement :: DataManipulation Tables '[] '[]
84+ statement :: Manipulation Tables '[] '[]
8585 statement = insertInto #table1 $ 2 `As` #col1 :* 4 `As` #col2 :* Nil
8686 statement `manipulationRenders`
8787 "INSERT INTO table1 (col1, col2) VALUES (2, 4);"
8888 it "correctly renders returning INSERTs" $ do
8989 let
90− statement :: DataManipulation Tables '[] SumAndCol1
90+ statement :: Manipulation Tables '[] SumAndCol1
9191 statement = insertIntoReturning #table1
9292 (2 `As` #col1 :* 4 `As` #col2 :* Nil)
9393 ((#col1 + #col2) `As` #sum :* #col1 `As` #col1 :* Nil)
@@ -95,7 +95,7 @@ spec = do
9595 "INSERT INTO table1 (col1, col2) VALUES (2, 4) RETURNING (col1 + col2) AS sum, col1 AS col1;"
9696 it "correctly renders simple UPDATEs" $ do
9797 let
98− statement :: DataManipulation Tables '[] '[]
98+ statement :: Manipulation Tables '[] '[]
9999 statement = update #table1
100100 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
101101 (#col1 /=* #col2)
@@ -103,7 +103,7 @@ spec = do
103103 "UPDATE table1 SET col1 = 2 WHERE (col1 <> col2);"
104104 it "correctly renders returning UPDATEs" $ do
105105 let
106− statement :: DataManipulation Tables '[] SumAndCol1
106+ statement :: Manipulation Tables '[] SumAndCol1
107107 statement = updateReturning #table1
108108 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
109109 (#col1 /=* #col2)
@@ -112,7 +112,7 @@ spec = do
112112 "UPDATE table1 SET col1 = 2 WHERE (col1 <> col2) RETURNING (col1 + col2) AS sum, col1 AS col1;"
113113 it "correctly renders upsert INSERTs" $ do
114114 let
115− statement :: DataManipulation Tables '[] '[]
115+ statement :: Manipulation Tables '[] '[]
116116 statement = upsertInto #table1
117117 (2 `As` #col1 :* 4 `As` #col2 :* Nil)
118118 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
@@ -121,7 +121,7 @@ spec = do
121121 "INSERT INTO table1 (col1, col2) VALUES (2, 4) ON CONFLICT UPDATE table1 SET col1 = 2 WHERE (col1 <> col2);"
122122 it "correctly renders returning upsert INSERTs" $ do
123123 let
124− statement :: DataManipulation Tables '[] SumAndCol1
124+ statement :: Manipulation Tables '[] SumAndCol1
125125 statement = upsertIntoReturning #table1
126126 (2 `As` #col1 :* 4 `As` #col2 :* Nil)
127127 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
@@ -131,13 +131,13 @@ spec = do
131131 "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;"
132132 it "correctly renders DELETEs" $ do
133133 let
134− statement :: DataManipulation Tables '[] '[]
134+ statement :: Manipulation Tables '[] '[]
135135 statement = deleteFrom #table1 (#col1 ==* #col2)
136136 statement `manipulationRenders`
137137 "DELETE FROM table1 WHERE (col1 = col2);"
138138 it "should be safe against SQL injection in literal text" $ do
139139 let
140− statement :: DataManipulation StudentsTable '[] '[]
140+ statement :: Manipulation StudentsTable '[] '[]
141141 statement = insertInto #students $
142142 "Robert'); DROP TABLE students;" `As` #name :* Nil
143143 statement `manipulationRenders`
@@ -209,7 +209,7 @@ spec = do
209209 "CREATE TABLE table2 (col1 serial, col2 text, col3 int8 NOT NULL DEFAULT 8);"
210210 it "should render DROP TABLE statements" $ do
211211 let
212− statement :: DataDefinition Tables '[]
212+ statement :: Definition Tables '[]
213213 statement = dropTable #table1
214214 statement `definitionRenders` "DROP TABLE table1;"
215215