2022-08-28 19:39:28 +02:00
|
|
|
use r2d2_mysql::{
|
|
|
|
mysql::{Opts, OptsBuilder},
|
2022-12-11 16:25:15 +01:00
|
|
|
MySqlConnectionManager,
|
2022-08-28 19:39:28 +02:00
|
|
|
};
|
2019-12-07 15:16:46 +01:00
|
|
|
|
2022-12-11 16:25:15 +01:00
|
|
|
pub type Pool = r2d2::Pool<MySqlConnectionManager>;
|
2019-12-07 15:16:46 +01:00
|
|
|
|
|
|
|
pub fn get_db_pool() -> Pool {
|
|
|
|
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
|
|
|
let opts = Opts::from_url(&db_url).unwrap();
|
|
|
|
let builder = OptsBuilder::from_opts(opts);
|
2022-12-11 16:25:15 +01:00
|
|
|
let manager = MySqlConnectionManager::new(builder);
|
2019-12-07 15:16:46 +01:00
|
|
|
r2d2::Pool::new(manager).expect("Failed to create DB Pool")
|
|
|
|
}
|