#mango #couch-db #nosql #client-side

mango_smoothie

A client side library for CouchDB Mango/Cloudant Query

4 releases

Uses old Rust 2015

0.2.0 Feb 5, 2017
0.1.2 Nov 25, 2016
0.1.1 Nov 25, 2016
0.1.0 Nov 24, 2016

#7 in #mango

MIT license

595KB
264 lines

Mango Smoothie Build Status

A CouchDB Mango/Cloudant query client for rust. It supports creating indexes, listing indexes and querying indexes

For (docs)http://garrensmith.com/mango_smoothie/

extern crate mango_smoothie;
use mango_smoothie::database;
#[macro_use]
extern crate serde_json;


let query_resp = db.query_index(json!({
                "selector": {
                    "diet": {
                        "$eq": "omnivore"
                    }
                },
                "fields": ["_id", "_rev", "name", "class", "diet"]
             }));

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

License

Mango Smoothie is licensed under MIT. See the LICENSE file for more


lib.rs:

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 uses the serde_json macro to help with querying indexes.

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

let query = json!({
   "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");

Dependencies

~8.5MB
~198K SLoC