2020-06-24 08:28:53 +00:00
|
|
|
use diesel::pg::PgConnection;
|
2020-06-26 02:44:19 +00:00
|
|
|
use diesel::r2d2::ConnectionManager;
|
2020-06-26 11:14:07 +00:00
|
|
|
use diesel::{r2d2, Connection};
|
2020-06-24 08:28:53 +00:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
pub type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;
|
|
|
|
|
|
|
|
pub fn pool() -> Pool {
|
|
|
|
let manager = ConnectionManager::<PgConnection>::new(database_url());
|
2021-07-29 06:09:42 +00:00
|
|
|
let pool_size = env::var("KATBIN_POOL_SIZE")
|
|
|
|
.unwrap()
|
|
|
|
.parse::<u32>()
|
|
|
|
.expect("pool size");
|
2020-11-22 18:59:39 +00:00
|
|
|
Pool::builder().max_size(pool_size).build(manager).unwrap()
|
2020-06-24 08:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn database_url() -> String {
|
|
|
|
env::var("DATABASE_URL").expect("DATABASE_URL must be set")
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pg_connection() -> PgConnection {
|
|
|
|
PgConnection::establish(database_url().as_str()).unwrap()
|
2020-06-26 11:14:07 +00:00
|
|
|
}
|