Bryan O'Sullivan avatar Bryan O'Sullivan committed e138bf0

Add put_ and putMany_.

Comments (0)

Files changed (3)

src/Network/Riak/JSON/Monoid.hs

       get
     , getMany
     , put
+    , put_
     , putMany
+    , putMany_
     ) where
 
 import Data.Aeson.Types (FromJSON(..), ToJSON(..))
 put = M.put J.put
 {-# INLINE put #-}
 
+-- | Store a single value, automatically resolving any vector clock
+-- conflicts that arise.  A single invocation of this function may
+-- involve several roundtrips to the server to resolve conflicts.
+--
+-- If a conflict arises, a winner will be chosen using 'mconcat', and
+-- the winner will be stored; this will be repeated until no conflict
+-- occurs.
+put_ :: (FromJSON c, ToJSON c, Monoid c) =>
+       Connection -> Bucket -> Key -> Maybe VClock -> c -> W -> DW
+    -> IO ()
+put_ = M.put_ J.put
+{-# INLINE put_ #-}
+
 -- | Store multiple values, resolving any vector clock conflicts that
 -- arise.  A single invocation of this function may involve several
 -- roundtrips to the server to resolve conflicts.
         -> IO [(c, VClock)]
 putMany = M.putMany J.putMany
 {-# INLINE putMany #-}
+
+-- | Store multiple values, resolving any vector clock conflicts that
+-- arise.  A single invocation of this function may involve several
+-- roundtrips to the server to resolve conflicts.
+--
+-- If any conflicts arise, a winner will be chosen in each case using
+-- 'mconcat', and the winners will be stored; this will be repeated
+-- until no conflicts occur.
+putMany_ :: (FromJSON c, ToJSON c, Monoid c) =>
+            Connection -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW
+         -> IO ()
+putMany_ = M.putMany_ J.putMany
+{-# INLINE putMany_ #-}

src/Network/Riak/Monoid.hs

+-- |
+-- Module:      Network.Riak.Monoid
+-- Copyright:   (c) 2011 MailRank, Inc.
+-- License:     Apache
+-- Maintainer:  Bryan O'Sullivan <bos@mailrank.com>
+-- Stability:   experimental
+-- Portability: portable
+--
+-- Storage and retrieval of monoidal data with automatic conflict resolution.
+
 module Network.Riak.Monoid
     (
       get
     , getMany
     , put
+    , put_
     , putMany
+    , putMany_
     ) where
 
 import Control.Arrow (first, second)
           _   -> go (mconcat xs) (Just vclock)
   go val0 mvclock0
 
+put_ :: Monoid c => (Connection -> Bucket -> Key -> Maybe VClock -> c -> W -> DW
+                                -> IO ([c], VClock))
+     -> Connection -> Bucket -> Key -> Maybe VClock -> c -> W -> DW
+     -> IO ()
+put_ doPut conn bucket key mvclock0 val0 w dw =
+    put doPut conn bucket key mvclock0 val0 w dw >> return ()
+{-# INLINE put_ #-}
+
 putMany :: (Monoid c) =>
            (Connection -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW
                        -> IO [([c], VClock)])
   asPut (i,(c,v)) = (i,(keys M.! i, Just v, mconcat c))
   keys = M.fromAscList (zip [(0::Int)..] (map fst3 puts0))
   fst3 (a,_,_) = a
+
+putMany_ :: (Monoid c) =>
+           (Connection -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW
+                       -> IO [([c], VClock)])
+        -> Connection -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW
+        -> IO ()
+putMany_ doPut conn bucket puts0 w dw =
+    putMany doPut conn bucket puts0 w dw >> return ()
+{-# INLINE putMany_ #-}

src/Network/Riak/Value/Monoid.hs

     , get
     , getMany
     , put
+    , put_
     , putMany
+    , putMany_
     ) where
 
 import Data.Monoid (Monoid(..))
 put = M.put V.put 
 {-# INLINE put #-}
 
+-- | Store a single value, automatically resolving any vector clock
+-- conflicts that arise.  A single invocation of this function may
+-- involve several roundtrips to the server to resolve conflicts.
+--
+-- If a conflict arises, a winner will be chosen using 'mconcat', and
+-- the winner will be stored; this will be repeated until no conflict
+-- occurs.
+put_ :: (Monoid c, V.IsContent c) =>
+        Connection -> Bucket -> Key -> Maybe VClock -> c -> W -> DW
+     -> IO ()
+put_ = M.put_ V.put 
+{-# INLINE put_ #-}
+
 -- | Store multiple values, resolving any vector clock conflicts that
 -- arise.  A single invocation of this function may involve several
 -- roundtrips to the server to resolve conflicts.
         -> IO [(c, VClock)]
 putMany = M.putMany V.putMany
 {-# INLINE putMany #-}
+
+-- | Store multiple values, resolving any vector clock conflicts that
+-- arise.  A single invocation of this function may involve several
+-- roundtrips to the server to resolve conflicts.
+--
+-- If any conflicts arise, a winner will be chosen in each case using
+-- 'mconcat', and the winners will be stored; this will be repeated
+-- until no conflicts occur.
+putMany_ :: (Monoid c, V.IsContent c) =>
+           Connection -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW
+        -> IO ()
+putMany_ = M.putMany_ V.putMany
+{-# INLINE putMany_ #-}
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.