2

I have a custom monad stack for my Servant app, which I'd like to keep to a single ReaderT without making it an "onion" over SqlPersistT or suchlike. Problem is, I haven't been able to find any code samples that do this.

It seems like most Persistent functions return an action in the following monad: (MonadIO m, PersistRecordBackend record backend) => ReaderT backend m record

Here's the definition of PersistRecordBackend:

type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend)

BaseBackend is part of the HasPersistentBackend type-class:

class HasPeristenBackend backend where
  type BaseBackend backend
  persistBackend :: backend -> BaseBackend backend

So, if I'm on the right track, either my custom AppM or Env will have to implement this HasPersistentBackend type-class.

data Env = Env {envDbPool, envLogger, envOtherStuff}
type AppM = ReaderT Env IO

Any help with getting this working would be appreciated. Finally, I'd like to be able to call runSqlPool directly in AppM (i.e. without any form of lift)

Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60

0 Answers0