It is easy to run DB actions in the normal Handler
workflow, since the runDB
function can be used to transform the SqlPersistM
actions into Handler
ones.
But there is no such way to convert SqlPersistM
directly into IO
using the default app settings. Looking at the Foundation.hs
as its 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 basically uses runSqlPool
with the app's config, but I don't see an easy way how to leverage this to access the config form within the REPL.
TL;DR: What I'm looking for is simply being able to do something like runDB $ selectList [...] [...]
from within cabal repl in my Yesod app, without having to duplicate the setup that Yesod scaffolding does out of the box.
When you click on the Database icon in the sidebar, you'll see some instructions. If your repl is in a language that has an official Database client, you can quickly import it and start using Database by clicking on the "Insert" buttons. If your language does not have a client, we provide some curl examples.
When viewing your repl, you'll find the Database icon toward the bottom of the sidebar – it's the second last icon. That’s Replit’s key-value database, built right into your repl!
Technically Repl.it DB is NoSQL. no, it's a key value database through and through. Why am I still asking questions about this? How does the code know that the user is the same as name?
We decided to sunset repl.run, which was a way to publish terminal apps as websites. repl.run urls will now redirect to the source repls where users can click "run" and use the repl. More information about what led to deprecation can be found here.
If you're using the Yesod scaffolding, the handler
and db
functions are provided to let you run handler actions and database queries, respectively, from the repl:
$ cabal repl
db $ selectList [UserName ==. "foo"] []
Edit: I've also updated Yesod's wiki page on GHCi with this information. It includes more examples and covers some advanced usage, like using the debugger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With