Commits

Anonymous committed b8722b1

Updated generic PUT

Comments (0)

Files changed (1)

src/Database/CouchDB/Enumerator/Generic.hs

 import Control.Applicative
 
 import Data.Data (Data)
-import qualified Data.Text as T
-import qualified Data.HashMap.Strict as H
+--import qualified Data.HashMap.Strict as H
 
 import qualified Network.HTTP.Types as HT
 
 import qualified Data.Aeson.Generic as AG
 
 import Database.CouchDB.Enumerator hiding (couchGet, couchPut)
-import qualified Database.CouchDB.Enumerator as CE (couchGet, couchPut)
+import qualified Database.CouchDB.Enumerator as CE (couchGet, couchPutRev)
 
 -- | CouchDB document with path (_id) and revision
 data CouchDoc a = CouchDoc Path (Maybe Revision) a deriving (Show)
 couchPut :: (MonadCouch m, Data a) =>
        Path             -- ^ the dbname is prepended to this string to 
                         --   form the full path.
-    -> Maybe Revision   -- ^ Revision. Nothing for new documents.
+    -> Revision         -- ^ Revision. Empty string for new documents.
     -> HT.Query         -- ^ Query arguments.
     -> a                -- ^ Data
     -> m Revision
 couchPut p r q a = 
-    CE.couchPut p q $ revInJson (AG.toJSON a) r
-  where
-    revInJson :: Value -> Maybe T.Text -> Value
-    revInJson (Object o) (Just rv) = Object $ H.insert "_rev" (toJSON rv) o
-    revInJson o _ = o
+    CE.couchPutRev p r q $ AG.toJSON a
     
 -- | Brute force version of 'couchPut'. Stores document regardless of presence
 --   in database (catches 'couchRev' 'CouchError' /404/). 
     -> a            -- ^ Data
     -> m Revision    
 couchPut' p q a = do
-    rev1 <- catch (do
-            r1 <- couchRev p
-            return $ Just r1)
-        handler
+    rev1 <- catch (couchRev p) handler
     couchPut p rev1 q a
   where
-    handler (CouchError (Just 404) _) = return Nothing
+    handler (CouchError (Just 404) _) = return ""
     handler e = throw e