12 releases (stable)

16.0.0 May 7, 2019
15.0.0 Mar 11, 2019
9.0.0 Jul 30, 2018
8.0.0 Jan 2, 2017
0.2.0 Jul 25, 2015

#71 in Database interfaces

Download history 51/week @ 2019-01-22 72/week @ 2019-01-29 73/week @ 2019-02-05 44/week @ 2019-02-12 74/week @ 2019-02-19 69/week @ 2019-02-26 60/week @ 2019-03-05 45/week @ 2019-03-12 51/week @ 2019-03-19 142/week @ 2019-03-26 56/week @ 2019-04-02 117/week @ 2019-04-09 50/week @ 2019-04-16 33/week @ 2019-04-23 36/week @ 2019-04-30

280 downloads per month
Used in 4 crates (3 directly)

MIT license

7KB
82 lines

r2d2-mysql

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

Install

Just include another [dependencies] section into your Cargo.toml:

[dependencies]
r2d2_mysql="*"

Example

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();
    }
}

Dependencies

~11MB
~198K SLoC