Permalink
Browse files

add couchPrefix

Signed-off-by: Alexander Dorofeev <aka.spin@gmail.com>
  • Loading branch information...
1 parent 1cfe6ab commit 725b6616feeeee449e96523815bd86f3bbd42596 @akaspin committed Mar 9, 2012
Showing with 12 additions and 4 deletions.
  1. +1 −1 ChangeLog
  2. +6 −2 src/Database/CouchDB/Conduit/Internal/Connection.hs
  3. +5 −1 src/Database/CouchDB/Conduit/LowLevel.hs
View
@@ -1,4 +1,4 @@
- 09.03.2012, Version 0.7.0 (Stable) * Rename `mkParam` to `viewQP` and add param name to arguments. * Add view query helpers. 09.03.2012, Version 0.6.0 (Stable) * Remove `couchPutView_` * Rename `couchPutView'` to `couchPutView` * `couchViewPost` and `couchViewPost'` * Remove `quoteQueryParam` * `mkParam` * Update deps constraints 15.02.2012, Version 0.5.3 (Stable) * Fix views with "update_seq" 04.02.2012, Version 0.5.1 (Stable) * Docs. * Quote query parameter helper. 03.02.2012, Version 0.5.0 (Stable) * Expose parser-independent methods in main module. * Expose Implicit methods. * Remove ambiguous database parameter from connection. * Add unambiguous database parameter in all methods. 03.02.2012, Version 0.4.2 * Update dependencies contraints. 24.01.2012, Version 0.4.1 * `couchSecureDB` lost db argument. 24.01.2012, Version 0.4.0 * Detailed error type. * Throw exception on `304`. * Database API lost db argument. * `couchViewPut*` -> `couchPutView` 22.01.2012, Version 0.3.0.1 * Constraints in cabal 19.01.2012, Version 0.3.0.0 * Fix for new http-conduit types 16.01.2012, Version 0.2.1.1 * Fixes for couchViewPut and couchSecureDB. 16.01.2012, Version 0.2.1 * Secure DB. 16.01.2012, Version 0.2.0.1 * Avoid escaping path in couch' 16.01.2012, Version 0.2.0 * Low-lewel API * "Don't care" versions of couchPut. * Brain-free couchRev'. * All database methods ignores DB in connection. * couchPutDB' renamed to couchPutDB_. * Database replication. 14.01.2012, Version 0.1.3.0 * Safe version of couchViewPut 14.01.2012, Version 0.1.2.0 * Authentification 11.01.2012, Version 0.1.1.0
+ 09.03.2012, Version 0.7.1 (Stable) * Add `couchPrefix` to `CouchConnection`. 09.03.2012, Version 0.7.0 (Stable) * Rename `mkParam` to `viewQP` and add param name to arguments. * Add view query helpers. 09.03.2012, Version 0.6.0 (Stable) * Remove `couchPutView_` * Rename `couchPutView'` to `couchPutView` * `couchViewPost` and `couchViewPost'` * Remove `quoteQueryParam` * `mkParam` * Update deps constraints 15.02.2012, Version 0.5.3 (Stable) * Fix views with "update_seq" 04.02.2012, Version 0.5.1 (Stable) * Docs. * Quote query parameter helper. 03.02.2012, Version 0.5.0 (Stable) * Expose parser-independent methods in main module. * Expose Implicit methods. * Remove ambiguous database parameter from connection. * Add unambiguous database parameter in all methods. 03.02.2012, Version 0.4.2 * Update dependencies contraints. 24.01.2012, Version 0.4.1 * `couchSecureDB` lost db argument. 24.01.2012, Version 0.4.0 * Detailed error type. * Throw exception on `304`. * Database API lost db argument. * `couchViewPut*` -> `couchPutView` 22.01.2012, Version 0.3.0.1 * Constraints in cabal 19.01.2012, Version 0.3.0.0 * Fix for new http-conduit types 16.01.2012, Version 0.2.1.1 * Fixes for couchViewPut and couchSecureDB. 16.01.2012, Version 0.2.1 * Secure DB. 16.01.2012, Version 0.2.0.1 * Avoid escaping path in couch' 16.01.2012, Version 0.2.0 * Low-lewel API * "Don't care" versions of couchPut. * Brain-free couchRev'. * All database methods ignores DB in connection. * couchPutDB' renamed to couchPutDB_. * Database replication. 14.01.2012, Version 0.1.3.0 * Safe version of couchViewPut 14.01.2012, Version 0.1.2.0 * Authentification 11.01.2012, Version 0.1.1.0
* API Changes. `couchViewPut` moved to Database.CouchDB.Design and lost
language argument.
* Tests. 10.01.2012, Version 0.1.0.1
@@ -19,6 +19,7 @@ module Database.CouchDB.Conduit.Internal.Connection (
couchManager,
couchLogin,
couchPass,
+ couchPrefix,
-- * Runtime enviroment and errors #runtime#
MonadCouch (..),
@@ -96,10 +97,13 @@ data CouchConnection = CouchConnection {
-- ^ 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 @@ withCouchConnection :: ResourceIO m =>
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}
@@ -56,7 +56,7 @@ couch meth path hdrs qs reqBody protectFn = do
, 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 @@ couch meth path hdrs qs reqBody protectFn = do
(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'.

0 comments on commit 725b661

Please sign in to comment.