Struct chill::action::execute_view::ExecuteView
[−]
[src]
pub struct ExecuteView<'a, T, P, StartKey, EndKey> where EndKey: Serialize, P: IntoViewPath, StartKey: Serialize, T: Transport + 'a {
// some fields omitted
}
Executes a view on the CouchDB server and returns the result.
Chill executes the view by sending an HTTP request to the CouchDB server to
GET
from or POST
to the view's path. For more details about executing
views, please see the CouchDB documentation.
Errors
The following are some errors that may occur when executing a view.
Error::NotFound |
The database, design document, or view does not exist. |
Error::Unauthorized |
The client lacks permission to execute the view. |
Examples
The following program demonstrates view execution.
extern crate chill; extern crate serde_json; let server = chill::testing::FakeServer::new().unwrap(); let client = chill::Client::new(server.uri()).unwrap(); // Create a database and populate it with some documents. client.create_database("/baseball").run().unwrap(); let create_player = |name, home_runs| { client.create_document("/baseball", &serde_json::builder::ObjectBuilder::new() .insert("name", name) .insert("home_runs", home_runs) .build()) .run() .unwrap(); }; create_player("Babe Ruth", 714); create_player("Hank Aaron", 755); create_player("Willie Mays", 660); client.create_document("/baseball", { &serde_json::builder::ObjectBuilder::new() .insert_object("views", |x| { x.insert_object("home_run", |x| { x.insert("map", r#"function(doc) { emit(doc.home_runs, doc.name); }"#) }) }) .build() }) .with_document_id("_design/stat") .run() .unwrap(); // Execute a view to get players with at least 700 home runs. let view_response = client.execute_view( "/baseball/_design/stat/_view/home_run") .with_descending(true) .with_end_key_inclusive(&700) .run() .unwrap(); let expected = vec![ "Hank Aaron - 755", "Babe Ruth - 714", ]; let got = view_response.rows() .iter() .map(|x| format!("{} - {}", x.value::<String>().unwrap(), x.key::<i32>().unwrap().unwrap())) .collect::<Vec<_>>(); assert_eq!(expected, got);
Methods
impl<'a, EndKey, P, StartKey, T> ExecuteView<'a, T, P, StartKey, EndKey> where EndKey: Serialize, P: IntoViewPath, StartKey: Serialize, T: Transport + 'a
[src]
fn with_reduce(self, reduce: bool) -> Self
Modifies the action to explicitly reduce or not reduce the view.
The with_reduce
method abstracts CouchDB's reduce
query parameter.
By default, CouchDB reduces a view if and only if the view contains a
reduction function. Consequently, an application may use this method to
disable reduction of a view that contains a reduction function.
fn with_limit(self, limit: u64) -> Self
Modifies the action to retrieve at most a given number of documents.
The with_limit
method abstracts CouchDB's limit
query parameter. By
default, the CouchDB server sends all rows.
This method has no effect if the view is reduced.
fn with_descending(self, descending: bool) -> Self
Modifies the action to retrieve the view rows in descending order.
The with_descending
method abstracts CouchDB's descending
query
parameter. By default, the CouchDB server sends the rows of an unreduced
view in ascending order, sorted by key. Whereas, if the descending
query parameter is true
, then the server sends the rows in reverse
order.
This method has no effect if the view is reduced.
fn with_exact_groups(self, yes_or_no: bool) -> Self
fn with_group_level(self, group_level: u32) -> Self
fn with_documents(self, yes_or_no: bool) -> Self
impl<'a, EndKey, P, T> ExecuteView<'a, T, P, (), EndKey> where EndKey: Serialize, P: IntoViewPath, T: Transport + 'a
[src]
fn with_start_key<StartKey>(self, start_key: StartKey) -> ExecuteView<'a, T, P, StartKey, EndKey> where StartKey: Serialize
Modifies the action to include only records with a key greater than or equal to a given key.
The with_start_key
method abstracts CouchDB's startkey
query
parameter. By default, the CouchDB server includes all records.
impl<'a, P, StartKey, T> ExecuteView<'a, T, P, StartKey, ()> where P: IntoViewPath, StartKey: Serialize, T: Transport + 'a
[src]
fn with_end_key_inclusive<EndKey>(self, end_key: EndKey) -> ExecuteView<'a, T, P, StartKey, EndKey> where EndKey: Serialize
Modifies the action to include only records with a key less than or equal to a given key.
The with_end_key_inclusive
method abstracts CouchDB's endkey
query
parameter. By default, the CouchDB server includes all records.
fn with_end_key_exclusive<EndKey>(self, end_key: EndKey) -> ExecuteView<'a, T, P, StartKey, EndKey> where EndKey: Serialize
Modifies the action to include only records with a key less than a given key.
The with_end_key_exclusive
method abstracts CouchDB's endkey
and
inclusive_end
query parameters. By default, the CouchDB server
includes all records.