@@ -45,17 +45,43 @@ import qualified Data.Text as Text
4545import Data.Text.Encoding ( encodeUtf8 )
4646
4747
48+-- | The constituent parts of an @UPDATE@ statement.
4849type Update :: Type -> Type
4950data Update a where
5051 Update :: Selects names exprs =>
5152 { target :: TableSchema names
53+ -- ^ Which table to update.
5254 , set :: exprs -> exprs
55+ -- ^ How to update each selected row.
5356 , updateWhere :: exprs -> Expr Bool
57+ -- ^ Which rows to select for update.
5458 , returning :: Returning names a
59+ -- ^ What to return from the @UPDATE@ statement.
5560 }
5661 -> Update a
5762
5863
64+-- | Run an @UPDATE@ statement.
65+--
66+-- >>> mapM_ print =<< select c (each projectSchema)
67+-- Project {projectAuthorId = 1, projectName = "rel8"}
68+-- Project {projectAuthorId = 2, projectName = "aeson"}
69+-- Project {projectAuthorId = 2, projectName = "text"}
70+--
71+-- >>> :{
72+-- update c Update
73+-- { target = projectSchema
74+-- , set = \p -> p { projectName = "Rel8!" }
75+-- , updateWhere = \p -> projectName p ==. lit "rel8"
76+-- , returning = NumberOfRowsAffected
77+-- }
78+-- :}
79+-- 1
80+--
81+-- >>> mapM_ print =<< select c (each projectSchema)
82+-- Project {projectAuthorId = 2, projectName = "aeson"}
83+-- Project {projectAuthorId = 2, projectName = "text"}
84+-- Project {projectAuthorId = 1, projectName = "Rel8!"}
5985update :: Update a -> Connection -> IO a
6086update Update {target, set, updateWhere, returning} =
6187 case returning of