rust-mysql-simple
support library for the r2d2
connection pool.
Documentation is available at http://outersky.github.io/r2d2-mysql/doc/v3.0.0/r2d2_mysql
Just include another [dependencies]
section into your Cargo.toml:
toml
[dependencies]
r2d2_mysql="*"
```rust,norun extern crate r2d2mysql; extern crate r2d2;
use std::sync::Arc; use std::thread;
fn main() { let dburl = "mysql://root:12345678@localhost:3306/test"; let config = r2d2::config::Builder::new().poolsize(5).build(); // r2d2::Config::default() let manager = r2d2mysql::MysqlConnectionManager::new(dburl).unwrap(); let pool = Arc::new(r2d2::Pool::new(config, manager).unwrap());
let mut tasks = vec![];
for i in 0..3 {
let pool = pool.clone();
let th = thread::spawn(move || {
let mut conn = pool.get().unwrap();
conn.query("select user()").unwrap();
println!("thread {} end!" , i );
});
tasks.push(th);
}
for th in tasks {
let _ = th.join();
}
} ```