snaplet-mongodb-minimalistic 0.0.6.5 → 0.0.6.6
raw patch · 3 files changed
+32/−34 lines, 3 filesdep +lensdep ~snapPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: lens
Dependency ranges changed: snap
API changes (from Hackage documentation)
- Snap.Snaplet.MongoDB.Functions.M: eitherWithDB :: (MonadIO m, MonadState app m) => Lens app (Snaplet MongoDB) -> Action IO a -> m (Either Failure a)
+ Snap.Snaplet.MongoDB.Functions.M: eitherWithDB :: (MonadIO m, MonadState app m) => SnapletLens app MongoDB -> Action IO a -> m (Either Failure a)
- Snap.Snaplet.MongoDB.Functions.M: eitherWithDB' :: (MonadIO m, MonadState app m) => Lens app (Snaplet MongoDB) -> AccessMode -> Action IO a -> m (Either Failure a)
+ Snap.Snaplet.MongoDB.Functions.M: eitherWithDB' :: (MonadIO m, MonadState app m) => SnapletLens app MongoDB -> AccessMode -> Action IO a -> m (Either Failure a)
- Snap.Snaplet.MongoDB.Functions.M: maybeWithDB :: (MonadIO m, MonadState app m) => Lens app (Snaplet MongoDB) -> Action IO a -> m (Maybe a)
+ Snap.Snaplet.MongoDB.Functions.M: maybeWithDB :: (MonadIO m, MonadState app m) => SnapletLens app MongoDB -> Action IO a -> m (Maybe a)
- Snap.Snaplet.MongoDB.Functions.M: maybeWithDB' :: (MonadIO m, MonadState app m) => Lens app (Snaplet MongoDB) -> AccessMode -> Action IO a -> m (Maybe a)
+ Snap.Snaplet.MongoDB.Functions.M: maybeWithDB' :: (MonadIO m, MonadState app m) => SnapletLens app MongoDB -> AccessMode -> Action IO a -> m (Maybe a)
- Snap.Snaplet.MongoDB.Functions.M: unsafeWithDB :: (MonadIO m, MonadState app m) => Lens app (Snaplet MongoDB) -> Action IO a -> m a
+ Snap.Snaplet.MongoDB.Functions.M: unsafeWithDB :: (MonadIO m, MonadState app m) => SnapletLens app MongoDB -> Action IO a -> m a
- Snap.Snaplet.MongoDB.Functions.M: unsafeWithDB' :: (MonadIO m, MonadState app m) => Lens app (Snaplet MongoDB) -> AccessMode -> Action IO a -> m a
+ Snap.Snaplet.MongoDB.Functions.M: unsafeWithDB' :: (MonadIO m, MonadState app m) => SnapletLens app MongoDB -> AccessMode -> Action IO a -> m a
Files
- snaplet-mongodb-minimalistic.cabal +3/−2
- src/Snap/Snaplet/MongoDB/Functions/M.hs +29/−31
- src/Snap/Snaplet/MongoDB/Functions/S.hs +0/−1
snaplet-mongodb-minimalistic.cabal view
@@ -1,5 +1,5 @@ Name: snaplet-mongodb-minimalistic-Version: 0.0.6.5+Version: 0.0.6.6 Synopsis: Minimalistic MongoDB Snaplet. Description: Minimalistic MongoDB Snaplet. License: BSD3@@ -33,8 +33,9 @@ Build-depends: base == 4.*,+ lens == 3.7.*, mtl == 2.*,- snap == 0.9.*,+ snap == 0.10.*, snap-core == 0.9.*, text == 0.11.*, mongoDB == 1.3.*
src/Snap/Snaplet/MongoDB/Functions/M.hs view
@@ -14,18 +14,18 @@ , unsafeWithDB' ) where +import Control.Monad (liftM) import Control.Monad.Error (runErrorT)+import Control.Lens (cloneLens, use) import Snap (MonadIO, MonadState, gets, liftIO) -- transformers, mtl-import Snap (Lens, getL) -- data-lens+import Snap (SnapletLens) import Snap (Snaplet, snapletValue) import Snap.Snaplet.MongoDB.Core import Database.MongoDB (Action, AccessMode, Failure (ConnectionFailure), access) import System.IO.Pool (aResource) -import qualified Control.Category as C ((.))- ------------------------------------------------------------------------------ -- | Database access function. --@@ -33,9 +33,9 @@ -- -- > unsafeWithDB accountDB $ insert "test-collection" [ "some_field" = "something" ] unsafeWithDB :: (MonadIO m, MonadState app m)- => Lens app (Snaplet MongoDB) -- ^ The snaplet (database) on which you want the action to be run.- -> Action IO a -- ^ 'Action' you want to perform.- -> m a -- ^ The action's result; in case of failure 'error' is called.+ => SnapletLens app MongoDB -- ^ The snaplet (database) on which you want the action to be run.+ -> Action IO a -- ^ 'Action' you want to perform.+ -> m a -- ^ The action's result; in case of failure 'error' is called. unsafeWithDB snaplet action = getMongoAccessMode snaplet >>= flip (unsafeWithDB' snaplet) action ------------------------------------------------------------------------------@@ -45,12 +45,12 @@ -- -- > unsafeWithDB' accountDB UnconfirmedWrites $ insert "test-collection" [ "some_field" = "something" ] unsafeWithDB' :: (MonadIO m, MonadState app m)- => Lens app (Snaplet MongoDB) -- ^ The snaplet (database) on which you want the action to be run.- -> AccessMode -- ^ Access mode you want to use when performing the action.- -> Action IO a -- ^ 'Action' you want to perform.- -> m a -- ^ The action's result; in case of failure 'error' is called.+ => SnapletLens app MongoDB -- ^ The snaplet (database) on which you want the action to be run.+ -> AccessMode -- ^ Access mode you want to use when performing the action.+ -> Action IO a -- ^ 'Action' you want to perform.+ -> m a -- ^ The action's result; in case of failure 'error' is called. unsafeWithDB' snaplet mode action = do- res <- (eitherWithDB' snaplet mode action)+ res <- eitherWithDB' snaplet mode action either (error . show) return res ------------------------------------------------------------------------------@@ -60,9 +60,9 @@ -- -- > maybeWithDB accountDB $ insert "test-collection" [ "some_field" = "something" ] maybeWithDB :: (MonadIO m, MonadState app m)- => Lens app (Snaplet MongoDB) -- ^ The snaplet (database) on which you want the action to be run.- -> Action IO a -- ^ 'Action' you want to perform.- -> m (Maybe a) -- ^ 'Nothing' in case of failure or 'Just' the result of the action.+ => SnapletLens app MongoDB -- ^ The snaplet (database) on which you want the action to be run.+ -> Action IO a -- ^ 'Action' you want to perform.+ -> m (Maybe a) -- ^ 'Nothing' in case of failure or 'Just' the result of the action. maybeWithDB snaplet action = getMongoAccessMode snaplet >>= flip (maybeWithDB' snaplet) action ------------------------------------------------------------------------------@@ -72,12 +72,12 @@ -- -- > maybeWithDB' accountDB UnconfirmedWrites $ insert "test-collection" [ "some_field" = "something" ] maybeWithDB' :: (MonadIO m, MonadState app m)- => Lens app (Snaplet MongoDB) -- ^ The snaplet (database) on which you want the action to be run.- -> AccessMode -- ^ Access mode you want to use when performing the action.- -> Action IO a -- ^ 'Action' you want to perform.- -> m (Maybe a) -- ^ 'Nothing' in case of failure or 'Just' the result of the action.+ => SnapletLens app MongoDB -- ^ The snaplet (database) on which you want the action to be run.+ -> AccessMode -- ^ Access mode you want to use when performing the action.+ -> Action IO a -- ^ 'Action' you want to perform.+ -> m (Maybe a) -- ^ 'Nothing' in case of failure or 'Just' the result of the action. maybeWithDB' snaplet mode action = do- res <- (eitherWithDB' snaplet mode action)+ res <- eitherWithDB' snaplet mode action return $ either (const Nothing) Just res ------------------------------------------------------------------------------@@ -87,9 +87,9 @@ -- -- > eitherWithDB accountDB $ insert "test-collection" [ "some_field" = "something" ] eitherWithDB :: (MonadIO m, MonadState app m)- => Lens app (Snaplet MongoDB) -- ^ The snaplet (database) on which you want the action to be run.- -> Action IO a -- ^ 'Action' you want to perform.- -> m (Either Failure a) -- ^ 'Either' 'Failure' or the action's result.+ => SnapletLens app MongoDB -- ^ The snaplet (database) on which you want the action to be run.+ -> Action IO a -- ^ 'Action' you want to perform.+ -> m (Either Failure a) -- ^ 'Either' 'Failure' or the action's result. eitherWithDB snaplet action = getMongoAccessMode snaplet >>= flip (eitherWithDB' snaplet) action ------------------------------------------------------------------------------@@ -99,19 +99,17 @@ -- -- > eitherWithDB' accountDB UnconfirmedWrites $ insert "test-collection" [ "some_field" = "something" ] eitherWithDB' :: (MonadIO m, MonadState app m)- => Lens app (Snaplet MongoDB) -- ^ The snaplet (database) on which you want the action to be run.- -> AccessMode -- ^ Access mode you want to use when performing the action.- -> Action IO a -- ^ 'Action' you want to perform.- -> m (Either Failure a) -- ^ 'Either' 'Failure' or the action's result.+ => SnapletLens app MongoDB -- ^ The snaplet (database) on which you want the action to be run.+ -> AccessMode -- ^ Access mode you want to use when performing the action.+ -> Action IO a -- ^ 'Action' you want to perform.+ -> m (Either Failure a) -- ^ 'Either' 'Failure' or the action's result. eitherWithDB' snaplet mode action = do- (MongoDB pool database _) <- gets (getL ((C..) snapletValue snaplet))+ (MongoDB pool database _) <- use (cloneLens snaplet . snapletValue) ep <- liftIO $ runErrorT $ aResource pool case ep of Left err -> return $ Left $ ConnectionFailure err Right pip -> liftIO $ access pip mode database action -getMongoAccessMode :: (MonadIO m, MonadState app m) => Lens app (Snaplet MongoDB) -> m AccessMode-getMongoAccessMode snaplet = gets (getL ((C..) snapletValue snaplet)) >>= return . mongoAccessMode+getMongoAccessMode :: (MonadIO m, MonadState app m) => SnapletLens app MongoDB -> m AccessMode+getMongoAccessMode snaplet = mongoAccessMode `liftM` use (cloneLens snaplet . snapletValue) {-# INLINE getMongoAccessMode #-}--
src/Snap/Snaplet/MongoDB/Functions/S.hs view
@@ -17,7 +17,6 @@ import Control.Monad.Error (runErrorT) import Snap (MonadIO, MonadState, gets, liftIO) -- transformers, mtl-import Snap (Lens, getL) -- data-lens import Snap (Snaplet, snapletValue) import Snap.Snaplet.MongoDB.Core