Crate mango_smoothie [] [src]

Mango Smoothie Mango Smoothie is a CouchDB Mango / Cloudant Query client library.

Create Indexes

To create an index first specify the url to the CouchDB/Cloudant instance, then specify the fields to be indexed.

 extern crate mango_smoothie;
 use mango_smoothie::{database};

 let resp = database("http://tester:testerpass@127.0.0.1:5984/animaldb").unwrap()
           .create_index(&["class", "name"]);

View Indexes

To list all the available indexes do the following:

   let indexes = database("http://tester:testerpass@127.0.0.1:5984/animaldb").unwrap()
               .list_indexes().unwrap();

   assert!(indexes.total_rows > 0);
   assert_eq!(indexes.indexes[0].name, "_all_docs".to_string());
   assert!(indexes.indexes[0].def.fields[0].contains_key(&"_id".to_string()));

Query Indexes

Mango Smoothie has a macro to help with querying indexes.

 #[macro_use]
 extern crate mango_smoothie;
 use mango_smoothie::{database};

 let query = query!({
    "selector" => {
       "_id" => {
         "$gt" => "1"
       }
     },
     "fields" => ["_id", "name"],
     "skip" => 3,
     "sort" => [{"_id" => "asc"}]
 });

 let query_resp = db.query_index(query).unwrap();
 assert_eq!(result.docs.len(), 5);
 let doc = &result.docs[0];
 assert_eq!(doc.get("class").unwrap().as_str().unwrap(), "mammal");

Modules

errors
http

Macros

query

The main query that processes the query and builds a BtreeMap that can be JSON serialized

query_type

Used to create a BtreeMap for each query section

Functions

database

The entry point for each Mango Smoothie request