[web-devel] [Yesod] [Persistent] PersistBackend and the ErrorT monad
mxcantor at gmail.com
Wed Aug 24 12:17:25 CEST 2011
0.5.1. sorry for forgetting to mention.
On Aug 24, 2011, at 6:09 PM, Michael Snoyman wrote:
> Is this on Persistent 0.5 or 0.6?
> On Wed, Aug 24, 2011 at 12:33 PM, Max Cantor <mxcantor at gmail.com> wrote:
> 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?
More information about the web-devel