We have a solution for exactly this problem in the Snap Framework.
It's called snaplets and it makes it really easy to do what you're
talking about. In fact, there are already two different snaplets
available on hackage that provide MongoDB support, so you probably
wouldn't even need to do it yourself. Snap's low-level API is very
similar to that of Happstack, so you shouldn't have too much trouble
converting if you already have code.
On Sun, Apr 1, 2012 at 4:58 AM, Lambda Dusk <lambdad
...@gmail.com> wrote:
> Hi,
> I am new to Happstack. Not so new to Haskell, but I have always had a big
> trouble designing monadic data types. It always seems simple, but I have
> some kind of mind block there.
> I have some server settings (for now, a database connection pool), and I
> want to put them into a ReaderT monad, that is then wrapped in the
> ServerPartT. Specifically, I have these two functions:
> withMongo :: (MongoPool -> IO a) -> IO ()
> withMongo f = do
> pool <- dbPool
> f pool
> killAll pool
> runDB :: (MonadIO m) => MongoPool -> Action IO a -> m (Either Failure a)
> runDB pool f = liftIO $ do
> pipe <- runIOE $ aResource pool
> access pipe master dbName f
> I would love to change "withMongo" in a way that I can drop it in before my
> "simpleHTTP" call. The type of runDB could be something like "Action IO a ->
> ServerPartT m (Either Failure a)" so it can be used in any handler without
> having to carry the pool with me all the time.
> I know this is not exactly a Happstack question, but I'd thought the chances
> are high someone on here has already done this specifically.
> Thanks.
> --
> You received this message because you are subscribed to the Google Groups
> "HAppS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/happs/-/cAJ2wiO-VgEJ.
> To post to this group, send email to happs@googlegroups.com.
> To unsubscribe from this group, send email to
> happs+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/happs?hl=en.