couchdb-conduit-0.6.0: Couch DB client library using http-conduit and aeson

Safe HaskellSafe-Infered

Database.CouchDB.Conduit.View

Contents

Description

Higher-level functions to interact with CouchDB views. To manipulate views in design documents see Database.CouchDB.Conduit.Design

Synopsis

Acccessing views

In contrast to the functions of access to documents that are loaded into memory entirely. couchView and couchView' combines the incredible power of http-conduit and attoparsec to allow you to process objects in constant space.

As data is read from the network, it is fed into attoparsec. When attoparsec completes parsing row, it sent to Sink. Sink can be composed from many conduits with sink at the end, such as rowValue, view conduits from Database.CouchDB.Conduit.Explicit and Database.CouchDB.Conduit.Generic, and many others. See Data.Conduit for details and documentation.

couchViewSource

Arguments

:: MonadCouch m 
=> Path

Database

-> Path

Design document

-> Path

View name

-> Query

Query parameters

-> ResourceT m (Source m Object) 

Run CouchDB view in manner like http.

 runCouch def $ do

     -- Print all upon receipt.
     src <- couchView "mydb" "mydesign" "myview" [] 
     src $$ CL.mapM_ (liftIO . print)

     -- ... Or extract row value and consume
     src' <- couchView "mydb" "mydesign" "myview" [] 
     res <- src' $= rowValue $$ CL.consume

couchView'Source

Arguments

:: MonadCouch m 
=> Path

Database

-> Path

Design document

-> Path

View name

-> Query

Query parameters

-> Sink Object m a

Sink for handle view rows.

-> ResourceT m a 

Brain-free version of couchView. Takes Sink to consume response.

 runCouch def $ do

     -- Print all upon receipt.
     couchView' "mydb" "mydesign" "myview" [] $ CL.mapM_ (liftIO . print)

     -- ... Or extract row value and consume
     res <- couchView' "mydb" "mydesign" "myview" [] $ 
                        rowValue =$ CL.consume

couchViewPostSource

Arguments

:: (MonadCouch m, ToJSON a) 
=> Path

Database

-> Path

Design document

-> Path

View name

-> Query

Query parameters

-> a

View keys. Must be list or cortege.

-> ResourceT m (Source m Object) 

Run CouchDB view in manner like http using POST (since CouchDB 0.9). It's convenient in case that keys paremeter too big for GET query string. Other query parameters used as usual.

 runCouch def $ do
     src <- couchViewPost "mydb" "mydesign" "myview" 
             [("group", Just "true")]
             ["key1", "key2", "key3"] 
     src $$ CL.mapM_ (liftIO . print)

couchViewPost'Source

Arguments

:: (MonadCouch m, ToJSON a) 
=> Path

Database

-> Path

Design document

-> Path

View name

-> Query

Query parameters

-> a

View keys. Must be list or cortege.

-> Sink Object m a

Sink for handle view rows.

-> ResourceT m a 

Brain-free version of couchViewPost. Takes Sink to consume response.

rowValue :: ResourceIO m => Conduit Object m ValueSource

Conduit for extract "value" field from CouchDB view row.

View query parameters

For details see http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options. Note, because all options must be a proper URL encoded JSON, construction of complex parameters can be very tedious. To simplify this, use mkParam.

mkParamSource

Arguments

:: ToJSON a 
=> a

Parameter

-> ByteString 

Encode query parameter to ByteString.

 mkParam (["a", "b"] :: [String])
 "[\"a\",\"b\"]"

It't just convert lazy ByteString from encode to strict ByteString