How to reuse a db action

11 views
Skip to first unread message

kees Bleijenberg

unread,
Mar 4, 2022, 6:17:38 AM3/4/22
to Yesod Web Framework
In a handler I save a Person with runDB a Esqueleto action (Postgress). I need this also in another handler.
How do I extract the savePerson code and place it in seperate function, so that in both handlers I can do: savePerson person.
I have problems with the type for this function. A simple example would be nice.

I understand that the db action needs the pooling. I tried getDBRunner, but no luck.

Jakob Schöttl

unread,
Mar 4, 2022, 6:22:55 AM3/4/22
to yeso...@googlegroups.com, kees Bleijenberg
I have common helper functions like this in my code:

deletePersonR :: PersonId -> Handler Html
deletePersonR personId = do
    _ <- runDB $ delete personId
    redirect PersonIndexR

The result of runDB is just Handler a (from the Import module).

I don't have experience with Esqueleto and pooling though.

- Jakob

Am 04.03.22 um 12:17 schrieb kees Bleijenberg:
Reply all
Reply to author
Forward
0 new messages