packages feed

couchdb-conduit 0.7.0 → 0.7.1

raw patch · 3 files changed

+12/−4 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

couchdb-conduit.cabal view
@@ -1,5 +1,5 @@ name:           couchdb-conduit-version:        0.7.0
+version:        0.7.1
 cabal-version:  >= 1.8 build-type:     Simple stability:      Stable
src/Database/CouchDB/Conduit/Internal/Connection.hs view
@@ -19,6 +19,7 @@     couchManager,
     couchLogin,
     couchPass,
+    couchPrefix,
     
     -- * Runtime enviroment and errors #runtime#
     MonadCouch (..),
@@ -96,10 +97,13 @@         -- ^ CouchDB login. By default is 'B.empty'.
     , couchPass :: B.ByteString
         -- ^ CouchDB password. By default is 'B.empty'.
+    , couchPrefix :: B.ByteString
+        -- ^ CouchDB database prefix. It will prepended to DB pathes.
+        --   Must be fully valid DB name fragment.
 }
 
 instance Default CouchConnection where
-    def = CouchConnection "localhost" 5984 Nothing B.empty B.empty
+    def = CouchConnection "localhost" 5984 Nothing B.empty B.empty B.empty
 
 -----------------------------------------------------------------------------
 -- Runtime
@@ -155,7 +159,7 @@        CouchConnection              -- ^ Couch connection
     -> (CouchConnection -> m a)     -- ^ Function to run
     -> m a
-withCouchConnection c@(CouchConnection _ _ mayMan  _ _) f = 
+withCouchConnection c@(CouchConnection _ _ mayMan  _ _ _) f = 
     case mayMan of
         -- Allocate manager with helper
         Nothing -> H.withManager $ \m -> lift $ f $ c {couchManager = Just m}
src/Database/CouchDB/Conduit/LowLevel.hs view
@@ -56,7 +56,7 @@             , H.host            = couchHost conn
             , H.requestHeaders  = hdrs
             , H.port            = couchPort conn
-            , H.path            = path
+            , H.path            = withPrefix $ couchPrefix conn
             , H.queryString     = HT.renderQuery False qs
             , H.requestBody     = reqBody
             , H.checkStatus = const . const $ Nothing }
@@ -65,6 +65,10 @@             (couchLogin conn) (couchPass conn) req
     res <- H.http req' (fromJust $ couchManager conn)
     protectFn res
+  where
+    withPrefix prx 
+        | B.null prx = path
+        | otherwise = prx `B.append` path 
 
 -- | Protect 'H.Response' from bad status codes. If status code in list 
 --   of status codes - just return response. Otherwise - throw 'CouchError'.