Document runDB

My coworker who is new to Haskell was pointing out that for such an important function to Yesod, this one is lacking any documentation. It's slightly hard to document because people could provide various implementations for it, but I think this description captures the essence pretty well, and notes the important implicit behavior of opening a transaction.
This commit is contained in:
Maximilian Tagher 2019-03-06 11:31:38 -08:00
parent c7e4dd0a1c
commit 837b898b35

View File

@ -41,6 +41,15 @@ type YesodDB site = ReaderT (YesodPersistBackend site) (HandlerFor site)
class Monad (YesodDB site) => YesodPersist site where
type YesodPersistBackend site
-- | Allows you to execute database actions within Yesod Handlers. For databases that support it, code inside the action will run as an atomic transaction.
--
--
-- ==== __Example Usage__
--
-- > userId <- runDB $ do
-- > userId <- insert $ User "username" "email@example.com"
-- > insert_ $ UserPreferences userId True
-- > pure userId
runDB :: YesodDB site a -> HandlerFor site a
-- | Helper for creating 'runDB'.