Crate r2d2_mysql [−] [src]
r2d2-mysql
MySQL support for the r2d2 connection pool (Rust) . see r2d2
.
Install
Just include another [dependencies.*]
section into your Cargo.toml:
[dependencies.r2d2_mysql]
git = "https://github.com/outersky/r2d2-mysql"
version="0.2.0"
Sample
extern crate r2d2_mysql; extern crate r2d2; use std::sync::Arc; use std::thread; fn main() { let db_url = "mysql://root:12345678@localhost:3306/test"; let config = r2d2::config::Builder::new().pool_size(5).build(); // r2d2::Config::default() let manager = r2d2_mysql::MysqlConnectionManager::new(db_url).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(); } }
Reexports
pub use pool::MysqlConnectionManager; |
pub use param::connect; |
Modules
param | |
pool | |
url |