Struct couchdb::DesignBuilder [] [src]

pub struct DesignBuilder {
    // some fields omitted
}

Builder for constructing a design document.

Examples

use couchdb::{DesignBuilder, ViewFunction};
let design = DesignBuilder::new()
                 .build_view("foo",
                             "function(doc) { if (doc.foo) { emit(doc.name, doc.foo); } }",
                             |x| x)
                 .build_view("bar",
                             "function(doc) { if (doc.foo) { emit(doc.name, doc.bar); } }",
                             |x| x.set_reduce("_sum"))
                 .unwrap();
assert_eq!(design.views.get("foo").unwrap().map,
           "function(doc) { if (doc.foo) { emit(doc.name, doc.foo); } }".to_string());
assert_eq!(design.views.get("bar").unwrap().reduce,
           Some("_sum".to_string()));

Methods

impl DesignBuilder

fn new() -> Self

Constructs a builder containing an empty design document.

fn unwrap(self) -> Design

Returns the design document contained within the builder.

fn insert_view<T, U>(self, view_name: T, view_function: U) -> Self where T: Into<String>, U: Into<ViewFunction>

Adds a view function to the design document contained within the builder.

If the design document already contains a view with the same name then the new view function replaces the existing view function.

fn build_view<T, U, F>(self, view_name: T, map_function: U, f: F) -> Self where T: Into<String>, U: Into<String>, F: FnOnce(ViewFunctionBuilder) -> ViewFunctionBuilder

Builds a view function and adds it to the design document contained within the builder.

If the design document already contains a view with the same name then the new view function replaces the existing view function.

Trait Implementations

Derived Implementations

impl Debug for DesignBuilder

fn fmt(&self, __arg_0: &mut Formatter) -> Result