@@ -45,17 +45,43 @@ import qualified Data.Text as Text
45import Data.Text.Encoding ( encodeUtf8 )
45import Data.Text.Encoding ( encodeUtf8 )
48+-- | The constituent parts of an @UPDATE@ statement.
48type Update :: Type -> Type
49type Update :: Type -> Type
49data Update a where
50data Update a where
50 Update :: Selects names exprs =>
51 Update :: Selects names exprs =>
51 { target :: TableSchema names
52 { target :: TableSchema names
53+ -- ^ Which table to update.
52 , set :: exprs -> exprs
54 , set :: exprs -> exprs
55+ -- ^ How to update each selected row.
53 , updateWhere :: exprs -> Expr Bool
56 , updateWhere :: exprs -> Expr Bool
57+ -- ^ Which rows to select for update.
54 , returning :: Returning names a
58 , returning :: Returning names a
59+ -- ^ What to return from the @UPDATE@ statement.
56 -> Update a
61 -> Update a
64+-- | Run an @UPDATE@ statement.
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"}
73+-- { target = projectSchema
74+-- , set = \p -> p { projectName = "Rel8!" }
75+-- , updateWhere = \p -> projectName p ==. lit "rel8"
76+-- , returning = NumberOfRowsAffected
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!"}
59update :: Update a -> Connection -> IO a
85update :: Update a -> Connection -> IO a
60update Update {target, set, updateWhere, returning} =
86update Update {target, set, updateWhere, returning} =
61 case returning of
87 case returning of