1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![doc(html_root_url = "http://garrensmith.com/mango_smoothie/")]
//! Mango Smoothie

//! Mango Smoothie is a [CouchDB Mango](http://docs.couchdb.org/en/latest/api/database/find.html) /
//! [Cloudant Query](https://docs.cloudant.com/cloudant_query.html) client library.
//!
//!# Create Indexes
//!
//! To create an index first specify the url to the CouchDB/Cloudant instance, then
//! specify the fields to be indexed.
//!
//!```ignore
//! 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:
//!
//!``` ignore
//!   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.
//!
//!``` ignore
//! #[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");
//!```




#![feature(proc_macro)]
#![feature(custom_attribute)]

#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;

extern crate hyper;

pub mod http;
pub mod errors;
#[macro_use]
pub mod query;
mod database;
pub use database::database;