From 837b898b3518e3cf8cb8960c593bd3dd3f09be50 Mon Sep 17 00:00:00 2001 From: Maximilian Tagher Date: Wed, 6 Mar 2019 11:31:38 -0800 Subject: [PATCH] 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. --- yesod-persistent/Yesod/Persist/Core.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/yesod-persistent/Yesod/Persist/Core.hs b/yesod-persistent/Yesod/Persist/Core.hs index 6b9d58d7..4467c2cb 100644 --- a/yesod-persistent/Yesod/Persist/Core.hs +++ b/yesod-persistent/Yesod/Persist/Core.hs @@ -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'.