How can I run Yesod DB actions in REPL?

It is easy to run DB actions in a regular Handler workflow, as the runDB function can be used to convert SqlPersistM actions to Handler .

But there is no way to convert SqlPersistM directly into IO using the default application settings. If you look at Foundation.hs as defined in the application scaffold, there is the following instance

 instance YesodPersist App where type YesodPersistBackend App = SqlBackend runDB action = do master <- getYesod runSqlPool action $ appConnPool master instance YesodPersistRunner App where getDBRunner = defaultGetDBRunner appConnPool 

which mainly uses runSqlPool with application configuration, but I don't see an easy way to use this to access the configuration form in REPL.

TL DR: What I'm looking for is to just do something like runDB $ selectList [...] [...] from within the Kabbalah replacement in my Yesod application without duplicating the settings that make esod scaffolding out of the box.

+5
source share
1 answer

If you use Yesod forests, handler and db functions are provided so that you can run the handler actions and the query database, respectively, from repl:

 $ cabal repl db $ selectList [UserName ==. "foo"] [] 

Edit: I also updated the Yesod wiki page on GHCi with this information. It contains more examples and covers some advanced usage possibilities, such as using a debugger.

+4
source

Source: https://habr.com/ru/post/1213273/


All Articles