Commits

Kamil Ciemniewski  committed ae922eb

Fixed HasMongoDBState

  • Participants
  • Parent commits 8ad20c8

Comments (0)

Files changed (5)

File dist/build/HSsnaplet-mongoDB-0.1.o

Binary file modified.

File dist/build/Snap/Snaplet/MongoDB.hi

Binary file modified.

File dist/build/Snap/Snaplet/MongoDB.o

Binary file modified.

File dist/build/libHSsnaplet-mongoDB-0.1.a

Binary file modified.

File src/Snap/Snaplet/MongoDB.hs

 ------------------------------------------------------------------------------
 -- |
 class HasMongoDBState s where
-    getMongoDBState :: s -> MongoDBSnaplet
-    setMongoDBState :: MongoDBSnaplet -> s -> s
+    getMongoDBState :: Handler s s MongoDBSnaplet
+    setMongoDBState :: MongoDBSnaplet -> Handler s s ()
 
-    modifyMongoDBState :: (MongoDBSnaplet -> MongoDBSnaplet) -> s -> s
-    modifyMongoDBState f s = setMongoDBState (f $ getMongoDBState s) s
+    --modifyMongoDBState :: (MongoDBSnaplet -> MongoDBSnaplet) -> s -> s
+    --modifyMongoDBState s = setMongoDBState s getMongoDBState
 
 
 ------------------------------------------------------------------------------
 
 ------------------------------------------------------------------------------
 -- |
---instance HasMongoDBState s => MonadMongoDB (SnapExtend s) where
---  withDB run = do
---    (MongoDBState pool db) <- asks getMongoDBState
---    epipe <- liftIO $ runErrorT $ aResource pool
---    case epipe of
---      Left err -> return $ Left $ ConnectionFailure err
---      Right pipe -> do
---		liftIO (access pipe master db run)
-
---  withDBUnsafe run = do
---    (MongoDBState pool db) <- asks getMongoDBState
---    epipe <- liftIO $ runErrorT $ aResource pool
---    case epipe of
---      Left err -> return $ Left $ ConnectionFailure err
---      Right pipe -> do
---		liftIO (access pipe UnconfirmedWrites db run)
+instance HasMongoDBState s => MonadMongoDB (Handler s s) where
+  withDB run = do
+    (MongoDBSnaplet pool db) <- getMongoDBState
+    epipe <- liftIO $ runErrorT $ aResource pool
+    case epipe of
+      Left err -> return $ Left $ ConnectionFailure err
+      Right pipe -> do
+		liftIO (access pipe master db run)
+
+  withDBUnsafe run = do
+    (MongoDBSnaplet pool db) <- getMongoDBState
+    epipe <- liftIO $ runErrorT $ aResource pool
+    case epipe of
+      Left err -> return $ Left $ ConnectionFailure err
+      Right pipe -> do
+		liftIO (access pipe UnconfirmedWrites db run)
 
 
 ------------------------------------------------------------------------------