couchdb-conduit 0.5.2 → 0.5.3
raw patch · 3 files changed
+53/−7 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- couchdb-conduit.cabal +1/−1
- src/Database/CouchDB/Conduit/View.hs +11/−4
- test/Database/CouchDB/Conduit/Test/View.hs +41/−2
couchdb-conduit.cabal 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
src/Database/CouchDB/Conduit/View.hs view
@@ -72,8 +72,7 @@ -> 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 @@ _ <- 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 +
test/Database/CouchDB/Conduit/Test/View.hs view
@@ -33,7 +33,9 @@ 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 @@ 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