yesodweb / yesod-scaffold

The Yesod scaffolding, with branches for different versions.
MIT License
75 stars 39 forks source link

Add DB alias #69

Closed pbrisbin closed 6 years ago

pbrisbin commented 9 years ago

This is a place-holder so I don't forget about this. If someone wants to go ahead and do it, great. If not, I plan to PR this soon

Functions suitable to pass to runDB can use the following type alias:

type DB a = forall (m :: * -> *).
    (MonadIO m, Functor m) => ReaderT SqlBackend m a

This promotes composition and testing.

findAdmin :: UserId -> Handler (Maybe User)
findAdmin = runDB $ -- ...

getFooR = do
    muser <- findAdmin uid

This findAdmin can't be (easily) tested or composed into other runDB invocations.

findAdmin :: UserId -> DB (Maybe User)
findAdmin = -- ...

getFooR = do
    muser <- runDB $ findAdmin uid

This findAdmin can be composed into other runDB calls and easily tested with TestImport.runDB.

snoyberg commented 9 years ago

@pbrisbin bump

gregwebs commented 9 years ago

I always add this

pbrisbin commented 9 years ago

Sorry I vanished on this. I changed jobs and got busy with non-Haskell work. I still think this is valuable but I won't have the time to implement and test for probably a few more weeks.

parsonsmatt commented 6 years ago

This appears to be resolved