on master help sign in
Document Rel8.Statement.Delete
commit8c797737f6577930058744ad01be6edb61ab2fca authorOllie Charles <ollie@ocharles.org.uk> dateTue 23 Mar 2021, 16:18 (6 years ago) parentd4354b2
1 file changed+23
src/Rel8/Statement/Delete.hs+23
src/Rel8/Statement/Delete.hs+23
@@ -42,16 +42,39 @@ import qualified Data.Text as Text
4242import Data.Text.Encoding ( encodeUtf8 )
4343
4444
45+-- | The constituent parts of a @DELETE@ statement.
4546type Delete :: Type -> Type
4647data Delete a where
4748 Delete :: Selects names exprs =>
4849 { from :: TableSchema names
50+ -- ^ Which table to delete from.
4951 , deleteWhere :: exprs -> Expr Bool
52+ -- ^ Which rows should be selected for deletion.
5053 , returning :: Returning names a
54+ -- ^ What to return from the @DELETE@ statement.
5155 }
5256 -> Delete a
5357
5458
59+-- | Run a @DELETE@ statement.
60+--
61+-- >>> mapM_ print =<< select c (each projectSchema)
62+-- Project {projectAuthorId = 1, projectName = "rel8"}
63+-- Project {projectAuthorId = 2, projectName = "aeson"}
64+-- Project {projectAuthorId = 2, projectName = "text"}
65+--
66+-- >>> :{
67+-- delete c Delete
68+-- { from = projectSchema
69+-- , deleteWhere = \p -> projectName p ==. lit "rel8"
70+-- , returning = Projection projectName
71+-- }
72+-- :}
73+-- ["rel8"]
74+--
75+-- >>> mapM_ print =<< select c (each projectSchema)
76+-- Project {projectAuthorId = 2, projectName = "aeson"}
77+-- Project {projectAuthorId = 2, projectName = "text"}
5578delete :: Delete a -> Connection -> IO a
5679delete Delete {from, deleteWhere, returning} =
5780 case returning of