sfackler / r2d2

A generic connection pool for Rust
Apache License 2.0
1.51k stars 82 forks source link

Unsure how to deal with the removal of `r2d2::Config` #46

Closed sgrif closed 6 years ago

sgrif commented 6 years ago

Sorry to ask here, I'm not sure where a better place to ask is (there's no IRC or gitter link in the README)... crates.io has this function which I am completely stumped on how to migrate to 0.8.0. Any help would be appreciated.

pub fn diesel_pool(
    url: &str,
    config: r2d2::Config<PgConnection, r2d2_diesel::Error>,
) -> DieselPool {
    let mut url = Url::parse(url).expect("Invalid database URL");
    if env::var("HEROKU").is_ok() && !url.query_pairs().any(|(k, _)| k == "sslmode") {
        url.query_pairs_mut().append_pair("sslmode", "require");
    }
    let manager = ConnectionManager::new(url.into_string());
    r2d2::Pool::new(config, manager).unwrap()
}
sfackler commented 6 years ago

This is a reasonable place to ask! The analogous function would just I think be

pub fn diesel_pool(
    url: &str,
    builder: r2d2::Builder<ConnectionManager>,
) -> DieselPool {
    let mut url = Url::parse(url).expect("Invalid database URL");
    if env::var("HEROKU").is_ok() && !url.query_pairs().any(|(k, _)| k == "sslmode") {
        url.query_pairs_mut().append_pair("sslmode", "require");
    }
    let manager = ConnectionManager::new(url.into_string());
    builder.build(manager).unwrap()
}

You can also use build_unchecked to avoid the unwrap if you'd like.

sgrif commented 6 years ago

I'll give that a try, thanks!