haskell - How to querying the database inside the makeApplication function -
i'm attempting fork non-web service in yesod application, , needs interaction database. this post decided put service in makeapplication. service return value when things happen , store database. thus, i'm wondering whats best way this?
how run rundb $ insert $ stuff (t.pack "stuff")
inside makeapplication function?
edit: suggested michael made following helper function inside application.hs
rundbio conf foundation f = dbconf <- withyamlenvironment "config/postgresql.yml" (appenv conf) database.persist.loadconfig >>= database.persist.applyenv p <- database.persist.createpoolconfig (dbconf :: settings.persistconf) logger <- mklogger true stdout runloggingt (database.persist.runpool dbconf f p) (messageloggersource foundation logger)
and in makeapplication used so:
rundbio conf foundation $ dbid <- insert $ stuff (t.pack "some random stuff") string <- dbid liftio $ print string
however, i'm getting compile error:
no instance (resourcet-0.4.5:control.monad.trans.resource.monadresource io) arising use of 'insert'
am inputting wrong type runpool? or need make instance insert
? don't see why runmigration migrateall
works insert
not.
you can see demonstration of how run database action in io
monad in the scaffolding itself. need provide 2 pieces of information: how log queries, , database connection pool. factor code out helper function (e.g., rundbio
), , run rundbio $ insert $ stuff $ t.pack "stuff"
.
Comments
Post a Comment