Higher-level functions to interact with CouchDB views.
- couchView :: MonadCouch m => Path -> Path -> Query -> ResourceT m (Source m Object)
- couchView' :: MonadCouch m => Path -> Path -> Query -> Sink Object m a -> ResourceT m a
- rowValue :: ResourceIO m => Conduit Object m Value
- couchViewPut :: MonadCouch m => Path -> Path -> ByteString -> ByteString -> Maybe ByteString -> ResourceT m Revision
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.
:: MonadCouch m | |
=> Path | Design document |
-> Path | View name |
-> Query | Query parameters |
-> ResourceT m (Source m Object) |
Run CouchDB view in manner like http
.
runCouch def {couchDB="mydb"} $ do -- Print all upon receipt. src <- couchView "mydesign" "myview" [] src $$ CL.mapM_ (liftIO . print) -- ... Or extract row value and consume src' <- couchView "mydesign" "myview" [] res <- src' $= rowValue $$ CL.consume
rowValue :: ResourceIO m => Conduit Object m ValueSource
Conduit for extract "value" field from CouchDB view row.
Manipulating views
:: MonadCouch m | |
=> Path | Design document |
-> Path | View name |
-> ByteString | Language. "javascript" for example. |
-> ByteString | |
-> Maybe ByteString | |
-> ResourceT m Revision |
Helper for put new views in design documents.
Cauntion Current implementation kill all other info except views. Use wise.