18 releases (1 stable)

Uses old Rust 2015

1.0.0 Jan 2, 2018
1.0.0-rc1 Dec 23, 2017
0.99.0 Nov 29, 2017
0.15.0 Jul 23, 2017
0.5.0 Feb 6, 2016

#2590 in Database interfaces

Download history 1083/week @ 2023-11-07 945/week @ 2023-11-14 982/week @ 2023-11-21 896/week @ 2023-11-28 795/week @ 2023-12-05 1115/week @ 2023-12-12 799/week @ 2023-12-19 757/week @ 2023-12-26 615/week @ 2024-01-02 900/week @ 2024-01-09 927/week @ 2024-01-16 690/week @ 2024-01-23 717/week @ 2024-01-30 895/week @ 2024-02-06 1024/week @ 2024-02-13 1045/week @ 2024-02-20

3,749 downloads per month
Used in 16 crates (13 directly)

MIT license

5KB
58 lines

r2d2-diesel

Provides r2d2 support to allow connection pooling with Diesel.

Examples

The examples creates a connection pool with default settings for a PostgreSQL or SQLite database running on localhost, then creates a bunch of threads and acquires a connection from the pool for each thread.

Executable versions are in examples/ which you can run with cargo run --example postgres --features "diesel/postgres" or cargo run --example sqlite --features "diesel/sqlite".

extern crate diesel;
extern crate r2d2;
extern crate r2d2_diesel;

use std::thread;

use diesel::PgConnection;
use r2d2_diesel::ConnectionManager;

fn main() {
    let manager = ConnectionManager::<PgConnection>::new("postgres://localhost/");
    let pool = r2d2::Pool::builder().build(manager).expect("Failed to create pool.");

    for _ in 0..10i32 {
        let pool = pool.clone();
        thread::spawn(move || {
            let connection = pool.get();

            assert!(connection.is_ok());
        });
    }
}

Using diesel master branch

If you want to use diesel master's branch with r2d2-diesel you have to add the following section in your Cargo.toml file. If you're using a workspace, this needs to be in the Cargo.toml at the root of the workspace.

[patch.crates-io]
diesel = { git = "https://github.com/diesel-rs/diesel.git" }
diesel_infer_schema = { git = "https://github.com/diesel-rs/diesel.git" }
diesel_codegen = { git = "https://github.com/diesel-rs/diesel.git" }

Dependencies

~3.5–10MB
~82K SLoC