11 releases (7 stable)

15.0.0 Mar 11, 2019
9.0.0 Jul 30, 2018
8.0.0 Jan 2, 2017
7.1.0 Nov 20, 2016
0.2.0 Jul 25, 2015

#69 in Database interfaces

Download history 87/week @ 2018-11-26 76/week @ 2018-12-03 101/week @ 2018-12-10 89/week @ 2018-12-17 70/week @ 2018-12-24 41/week @ 2018-12-31 66/week @ 2019-01-07 44/week @ 2019-01-14 53/week @ 2019-01-21 63/week @ 2019-01-28 81/week @ 2019-02-04 43/week @ 2019-02-11 75/week @ 2019-02-18 56/week @ 2019-02-25 66/week @ 2019-03-04

280 downloads per month
Used in 2 crates

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

~8.5MB
~162K SLoC