diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-02-24 17:18:09 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-02-24 17:18:09 +0100 |
| commit | db0f14a163a087261db7360a90d6ac70fb92e884 (patch) | |
| tree | 4963b1342bba7e0b2123fa33b7a683141ab43a25 /src/main.rs | |
| parent | 288eadd3c42352deba28cfe062e79e673cb5d577 (diff) | |
| download | frippy-db0f14a163a087261db7360a90d6ac70fb92e884.tar.gz frippy-db0f14a163a087261db7360a90d6ac70fb92e884.zip | |
Use r2d2 as a ConnectionPool for diesel
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index cb4e384..6605693 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,10 @@ extern crate time; extern crate diesel_migrations; #[cfg(feature = "mysql")] extern crate diesel; +#[cfg(feature = "mysql")] +extern crate r2d2; +#[cfg(feature = "mysql")] +extern crate r2d2_diesel; #[macro_use] extern crate log; @@ -119,13 +123,16 @@ fn main() { #[cfg(feature = "mysql")] { if let Some(url) = mysql_url { - use diesel; - use diesel::Connection; - match diesel::mysql::MysqlConnection::establish(url) { - Ok(conn) => { - match embedded_migrations::run(&conn) { + use diesel::MysqlConnection; + use r2d2; + use r2d2_diesel::ConnectionManager; + + let manager = ConnectionManager::<MysqlConnection>::new(url.clone()); + match r2d2::Pool::builder().build(manager) { + Ok(pool) => { + match embedded_migrations::run(&*pool.get().expect("Failed to get connection")) { Ok(_) => { - bot.add_plugin(plugins::Factoids::new(conn)); + bot.add_plugin(plugins::Factoids::new(pool)); info!("Connected to MySQL server") } Err(e) => { |
