Skip to content

Commit

Permalink
withDB' simple wrapper to disregard exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ozataman committed Dec 22, 2010
1 parent 7f00b97 commit f9e8a95
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Snap/Extension/MongoDB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ import Snap.Types
class MonadSnap m => MonadMongoDB m where

----------------------------------------------------------------------------
-- |
-- | Run given MongoDB action against the database
withDB :: ReaderT Database (Action m) a -> m (Either Failure a)


----------------------------------------------------------------------------
-- | Same as 'withDB' but calls 'error' if there is an exception
withDB' :: ReaderT Database (Action m) a -> m a
withDB' run = do
r <- withDB run
either (error . show) return r



------------------------------------------------------------------------------
-- | Get strict ByteString to work directly with BSON auto-casting
instance Val B8.ByteString where
Expand All @@ -55,3 +64,4 @@ instance Val [Word8] where
val = val . fmap w2c
cast' x = fmap (fmap c2w) . cast' $ x
cast' _ = Nothing

0 comments on commit f9e8a95

Please sign in to comment.