Bryan O'Sullivan avatar Bryan O'Sullivan committed 0e5f9cf

Switch quorum types away from Maybe wrappers; add a put_ function.

Comments (0)

Files changed (3)

src/Network/Riak/Request.hs

 getServerInfo = GetServerInfoRequest
 {-# INLINE getServerInfo #-}
 
-get :: Bucket -> Key -> Maybe R -> Get.GetRequest
+get :: Bucket -> Key -> R -> Get.GetRequest
 get bucket key r = Get.GetRequest { Get.bucket = bucket
                                   , Get.key = key
-                                  , Get.r = fromQuorum <$> r }
+                                  , Get.r = fromQuorum r }
 {-# INLINE get #-}
 
-put :: Bucket -> Key -> Maybe VClock -> Content -> Maybe W -> Maybe DW
-    -> Bool -> Put.PutRequest
+put :: Bucket -> Key -> Maybe VClock -> Content -> W -> DW -> Bool
+    -> Put.PutRequest
 put bucket key mvclock cont mw mdw returnBody =
     Put.PutRequest bucket key (fromVClock <$> mvclock) cont
-                   (fromQuorum <$> mw) (fromQuorum <$> mdw) (Just returnBody)
+                   (fromQuorum mw) (fromQuorum mdw) (Just returnBody)
 {-# INLINE put #-}
 
-delete :: Bucket -> Key -> Maybe RW -> Del.DeleteRequest
-delete bucket key rw = Del.DeleteRequest bucket key (fromQuorum <$> rw)
+delete :: Bucket -> Key -> RW -> Del.DeleteRequest
+delete bucket key rw = Del.DeleteRequest bucket key (fromQuorum rw)
 {-# INLINE delete #-}
 
 listBuckets :: ListBucketsRequest

src/Network/Riak/Simple.hs

     -- * Data management
     , get
     , put
+    , put_
     , delete
     -- * Metadata
     , listBuckets
 getServerInfo :: Connection -> IO ServerInfo
 getServerInfo conn = exchange conn Req.getServerInfo
 
-get :: Connection -> T.Bucket -> T.Key -> Maybe R
+get :: Connection -> T.Bucket -> T.Key -> R
     -> IO (Seq.Seq Content, Maybe VClock)
 get conn bucket key r =
   Resp.get <$> exchangeMaybe conn (Req.get bucket key r)
 
 put :: Connection -> T.Bucket -> T.Key -> Maybe T.VClock
-    -> Content -> Maybe W -> Maybe DW -> Bool
+    -> Content -> W -> DW
     -> IO (Seq.Seq Content, Maybe VClock)
-put conn bucket key mvclock cont mw mdw returnBody =
-  Resp.put <$> exchange conn (Req.put bucket key mvclock cont mw mdw returnBody)
+put conn bucket key mvclock cont w dw =
+  Resp.put <$> exchange conn (Req.put bucket key mvclock cont w dw True)
 
-delete :: Connection -> T.Bucket -> T.Key -> Maybe RW -> IO ()
+put_ :: Connection -> T.Bucket -> T.Key -> Maybe T.VClock
+     -> Content -> W -> DW
+     -> IO ()
+put_ conn bucket key mvclock cont w dw =
+  exchange_ conn (Req.put bucket key mvclock cont w dw False)
+
+delete :: Connection -> T.Bucket -> T.Key -> RW -> IO ()
 delete conn bucket key rw = exchange_ conn $ Req.delete bucket key rw
 
 listBuckets :: Connection -> IO (Seq.Seq T.Bucket)

src/Network/Riak/Types/Internal.hs

     show (VClock s) = "VClock " ++ show (md5 s)
 
 data Quorum = Default
+            | One
+            | Quorum
             | All
-            | Quorum
-            | One
-              deriving (Eq, Enum, Show)
+              deriving (Bounded, Eq, Enum, Ord, Show)
 
 type RW = Quorum
 type R  = Quorum
 type W  = Quorum
 type DW = Quorum
 
-fromQuorum :: Quorum -> Word32
-fromQuorum Default = 4294967291
-fromQuorum All     = 4294967292
-fromQuorum Quorum  = 4294967293
-fromQuorum One     = 4294967294
+fromQuorum :: Quorum -> Maybe Word32
+fromQuorum Default = Just 4294967291
+fromQuorum One     = Just 4294967294
+fromQuorum Quorum  = Just 4294967293
+fromQuorum All     = Just 4294967292
 {-# INLINE fromQuorum #-}
 
 toQuorum :: Word32 -> Maybe Quorum
+toQuorum 4294967294 = Just One
+toQuorum 4294967293 = Just Quorum
+toQuorum 4294967292 = Just All
 toQuorum 4294967291 = Just Default
-toQuorum 4294967292 = Just All
-toQuorum 4294967293 = Just Quorum
-toQuorum 4294967294 = Just One
-toQuorum _          = Nothing
+toQuorum v          = error $ "invalid quorum value " ++ show v
 {-# INLINE toQuorum #-}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.