Skip to content

Instantly share code, notes, and snippets.

@scorphus
Created September 4, 2016 06:15
Show Gist options
  • Select an option

  • Save scorphus/463ce04b148c6c890e2179db464fcb7f to your computer and use it in GitHub Desktop.

Select an option

Save scorphus/463ce04b148c6c890e2179db464fcb7f to your computer and use it in GitHub Desktop.
Using a connection pool for CouchDB in Rust with r2d2-couchdb
extern crate r2d2;
extern crate r2d2_couchdb;
extern crate serde_json;
use r2d2_couchdb::{CouchdbConnectionManager};
use std::thread;
use std::time::Duration;
fn main() {
let config = r2d2::Config::default();
let manager = CouchdbConnectionManager::new("http://localhost:5984/").unwrap();
let pool = r2d2::Pool::new(config, manager).unwrap();
for i in 0..2222u16 {
let pool = pool.clone();
thread::spawn(move || {
let content = serde_json::builder::ObjectBuilder::new()
.insert("foo", i)
.unwrap();
let conn = pool.get().unwrap();
conn.create_document("/ubicker", &content).run().unwrap();
println!("Sent {}", &content);
});
}
thread::sleep(Duration::new(7, 0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment