[Persistent] PersistBackend and the ErrorT monad

9 views
Skip to first unread message

Max Cantor

unread,
Aug 24, 2011, 5:33:43 AM8/24/11
to yeso...@googlegroups.com, web-devel
Hi,

I am trying to use an ErrorT monad inside some Persist code.

I wrote the following instance:

newtype OcrError = OE String
...
instance PersistBackend m => PersistBackend (ErrorT OcrError m) where
replace k v = lift $ replace k v
update k l = lift $ update k l
updateWhere f u = lift $ updateWhere f u
delete = lift . delete
insert = lift . insert
deleteBy = lift . deleteBy
deleteWhere = lift . deleteWhere
get = lift . get
getBy = lift . getBy
count = lift . count
selectKeys f = selectKeys f
selectEnum f o lim off = selectEnum f o lim off

It seems like there is a problem with selectEnum though.

In GHCI, this:

l :: [PersistKV OcrRefMap] <- rs $ selectEnum [] [] 0 0

works fine, while this:

l :: Either OcrError [PersistKV OcrRefMap] <- rs $ runErrorT $ selectEnum [] [] 0 0

hangs. rs is a small function to run persist calls:
rs :: (MonadControlIO m) => SqlPersist m a -> m a
rs f = do
let conn = DT.pack "user=hachicode password=password host=localhost port=5432 dbname=hachicode"
withPostgresqlConn conn $ runSqlConn f

and you need -XScopedTypeVariables for the ghci commands.

Any advice?

Thanks,
Max

Michael Snoyman

unread,
Aug 24, 2011, 6:09:16 AM8/24/11
to yeso...@googlegroups.com, web-devel
Is this on Persistent 0.5 or 0.6?

Max Cantor

unread,
Aug 24, 2011, 6:17:25 AM8/24/11
to yeso...@googlegroups.com, web-devel
0.5.1. sorry for forgetting to mention.

max

Michael Snoyman

unread,
Aug 24, 2011, 9:35:32 AM8/24/11
to yeso...@googlegroups.com
Well, here's a version. It can almost certainly be cleaned up by using monad-control. Let me know if that works for you.

Michael Snoyman

unread,
Aug 24, 2011, 9:38:22 AM8/24/11
to yeso...@googlegroups.com
It would help if I sent the link...

Max Cantor

unread,
Aug 24, 2011, 8:47:53 PM8/24/11
to yeso...@googlegroups.com, Michael Snoyman
worked like a charm. thanks michael!
Reply all
Reply to author
Forward
0 new messages