Permalink
Browse files

Fix bug with "update_seq"

Signed-off-by: Alexander Dorofeev <aka.spin@gmail.com>
  • Loading branch information...
akaspin committed Feb 15, 2012
1 parent 40cb061 commit e319bdfa9c3e34dee873414cc1ab0cfc3627f13e
Showing with 54 additions and 8 deletions.
  1. +1 −1 ChangeLog
  2. +1 −1 couchdb-conduit.cabal
  3. +11 −4 src/Database/CouchDB/Conduit/View.hs
  4. +41 −2 test/Database/CouchDB/Conduit/Test/View.hs
View
@@ -1,4 +1,4 @@
- 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
+ 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
View
@@ -1,5 +1,5 @@
name: couchdb-conduit
-version: 0.5.2
+version: 0.5.3
cabal-version: >= 1.8
build-type: Simple
stability: Stable
@@ -72,8 +72,7 @@ couchView :: MonadCouch m =>
-> HT.Query -- ^ Query parameters
-> ResourceT m (Source m A.Object)
couchView db designDocName viewName q = do
- H.Response _ _ bsrc <- couch HT.methodGet fullPath []
- (("update_seq", Just "false"):q)
+ H.Response _ _ bsrc <- couch HT.methodGet fullPath [] q
(H.RequestBodyBS B.empty) protect'
return $ bsrc $= conduitCouchView
where
@@ -149,12 +148,20 @@ viewStart = do
_ <- string "{"
_ <- option "" $ string "\"total_rows\":"
option () $ skipWhile (\x -> x >= 48 && x <= 57)
+ _ <- option "" $ string ",\"update_seq\":"
+ option () $ skipWhile (\x -> x >= 48 && x <= 57)
_ <- option "" $ string ",\"offset\":"
option () $ skipWhile (\x -> x >= 48 && x <= 57)
_ <- option "" $ string ","
_ <- string "\"rows\":["
- (string "]}" >> return False) <|> return True
-
+ (string "]}" <|> (do
+ r <- string "]"
+ _ <- option "" $ string ",\"update_seq\":"
+ option () $ skipWhile (\x -> x >= 48 && x <= 57)
+ _ <- option "" $ string "}"
+ return r)
+ >> return False) <|> return True
+
@@ -33,7 +33,9 @@ tests :: Test
tests = mutuallyExclusive $ testGroup "View" [
testCase "Create" caseCreateView,
testCase "Big values parsing" caseBigValues,
- testCase "View with reduce" caseWithReduce
+ testCase "With reduce" caseWithReduce,
+ testCase "update_seq before rows" caseUpdateSeqTop,
+ testCase "update_seq after rows" caseUpdateSeqAfter
]
data T = T {
@@ -93,6 +95,43 @@ caseWithReduce = bracket_
where
db = "cdbc_test_view_reduce"
doc n = T "doc" n $ show n
-
+
+caseUpdateSeqTop :: Assertion
+caseUpdateSeqTop = bracket_
+ (runCouch conn $ do
+ couchPutDB_ db
+ _ <- couchPutView' db "mydesign" "myview"
+ "function(doc){emit(doc.intV, doc.intV);}" Nothing
+ mapM_ (\n -> CCG.couchPut' db (docName n) [] $ doc n) [1..20])
+ (tearDB db) $ runCouch conn $ do
+ res <- couchView' db "mydesign" "myview"
+ [("update_seq",Just "true"),("key",Just "1")] $
+ (rowValue =$= CCG.toType) =$ CL.consume
+ liftIO $ res @=? [ReducedView 1]
+ where
+ db = "cdbc_test_view_before"
+ doc n = T "doc" n $ show n
+
+caseUpdateSeqAfter :: Assertion
+caseUpdateSeqAfter = bracket_
+ (runCouch conn $ do
+ couchPutDB_ db
+ _ <- couchPutView' db "mydesign" "myview"
+ "function(doc){emit([doc.intV,doc.intV], doc.intV);}" Nothing
+ mapM_ (\n -> CCG.couchPut' db (docName n) [] $ doc n) [1..20])
+ (tearDB db) $ runCouch conn $ do
+ res <- couchView' db "mydesign" "myview"
+ [("keys",Just "[[0,0]]")] $
+ (rowValue =$= CCG.toType) =$ CL.consume
+ liftIO $ res @=? ([] :: [ReducedView])
+ res' <- couchView' db "mydesign" "myview"
+ [] $
+ (rowValue) =$ CL.consume
+ liftIO $ print (res')
+
+ where
+ db = "cdbc_test_view_after"
+ doc n = T "doc" n $ show n
+
docName :: Int -> B.ByteString
docName n = fromString $ "doc" ++ show n

0 comments on commit e319bdf

Please sign in to comment.