Safe Haskell | Safe-Infered |
---|
Higher-level functions to interact with CouchDB views. To manipulate views in design documents see Database.CouchDB.Conduit.Design
- couchView :: MonadCouch m => Path -> Path -> Path -> Query -> m (Source m Object)
- couchView' :: MonadCouch m => Path -> Path -> Path -> Query -> Sink Object m a -> m a
- couchViewPost :: (MonadCouch m, ToJSON a) => Path -> Path -> Path -> Query -> a -> m (Source m Object)
- couchViewPost' :: (MonadCouch m, ToJSON a) => Path -> Path -> Path -> Query -> a -> Sink Object m a -> m a
- rowValue :: Monad m => Conduit Object m Value
- viewQpUnit :: HashMap ByteString Bool
- viewQp :: ToJSON a => ByteString -> a -> QueryItem
- viewQpBS :: ByteString -> ByteString -> QueryItem
- viewQpInt :: ByteString -> Int -> QueryItem
- viewQpTrue :: ByteString -> QueryItem
- viewQpFalse :: ByteString -> QueryItem
- viewQpDescending :: QueryItem
- viewQpLimit :: Int -> QueryItem
- viewQpSkip :: Int -> QueryItem
- viewQpStartId :: Path -> QueryItem
- viewQpEndId :: Path -> QueryItem
- viewQpGroup :: QueryItem
- viewQpGroupLevel :: Int -> QueryItem
- viewQpReduceOff :: QueryItem
- viewQpReduceOn :: QueryItem
- viewQpKey :: ToJSON a => a -> QueryItem
- viewQpStartKey :: ToJSON a => a -> QueryItem
- viewQpEndKey :: ToJSON a => a -> QueryItem
- viewQpKeys :: ToJSON a => a -> QueryItem
- viewQpIncludeDocs :: QueryItem
- viewQpInclusiveEnd :: QueryItem
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 | Database |
-> Path | Design document |
-> Path | View name |
-> Query | Query parameters |
-> 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
:: (MonadCouch m, ToJSON a) | |
=> Path | Database |
-> Path | Design document |
-> Path | View name |
-> Query | Query parameters |
-> a | View |
-> 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)
:: (MonadCouch m, ToJSON a) | |
=> Path | Database |
-> Path | Design document |
-> Path | View name |
-> Query | Query parameters |
-> a | View |
-> Sink Object m a | Sink for handle view rows. |
-> m a |
Brain-free version of couchViewPost
. Takes Sink
to consume response.
rowValue :: Monad 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 following functions.
viewQpUnit :: HashMap ByteString BoolSource
Not query parameter. Returns empty HashMap
. Aeson will convert
this to {}
(JSON unit). This useful for startkey
and endkey
.
:: ToJSON a | |
=> ByteString | Query parameter name |
-> a | Parameter |
-> QueryItem |
Make complex view query parameter.
viewQP "key" (["a", "b"] :: [String]) ("key", Just "[\"a\",\"b\"]")
It't just convert lazy ByteString
from encode
to strict
ByteString
. For more efficient use specific functions.
viewQpBS :: ByteString -> ByteString -> QueryItemSource
Make quoted ByteString
query parameter.
viewQpTrue :: ByteString -> QueryItemSource
Make ...=true
query parameter.
viewQpFalse :: ByteString -> QueryItemSource
Make ...=true
query parameter.
Rows
Helpers for sorting and limiting rows.
viewQpDescending :: QueryItemSource
Turn on descending sort of view results.
Shorthand for viewQpTrue "descending"
.
Limit view rows.
Shorthand for viewQpInt "limit"
.
Skip view rows.
Shorthand for viewQpInt "skip"
.
Document id to start with.
Shorthand for viewQpBS "startkey_docid"
.
Last document id to include in the output.
Shorthand for viewQpBS "endkey_docid"
.
Map/Reduce
Helpers for Map/Reduce.
viewQpGroup :: QueryItemSource
Turn on grouping.
Shorthand for viewQpTrue "group"
.
Set grouping level.
Shorthand for viewQpInt "group_level"
.
viewQpReduceOff :: QueryItemSource
Force off reduce if a reduce function is defined.
Shorthand for viewQpFalse "reduce"
.
viewQpReduceOn :: QueryItemSource
Force on reduce if a reduce function is not defined.
Shorthand for viewQpTrue "reduce"
.
Keys
Helpers for quering by keys.
Make key=...
query parameter.
Shorthand for viewQp "key"
.
Row key to start with.
Shorthand for viewQp startkey
Row key to end with.
Shorthand for viewQp endkey
Make keys=...
query parameter.
Shorthand for viewQp "keys"
.
Use it only with couchView
and couchView'
. For large sets of keys
use couchViewPost
and couchViewPost'
Control
Helpers for view behaviour.
viewQpIncludeDocs :: QueryItemSource
Turn on inclusion docs in view results.
Shorthand for viewQpTrue "include_docs"
.
viewQpInclusiveEnd :: QueryItemSource
Turn off inclusion endkey
in view results.
Shorthand for viewQpFalse "inclusive_end"
.