Refactored the whole code to a better structure

This commit is contained in:
Marko Korhonen 2020-04-05 22:53:42 +03:00
parent 87cc8ac794
commit 12b865bf17
No known key found for this signature in database
GPG key ID: 911B85FBC6003FE5
21 changed files with 473 additions and 257 deletions

View file

@ -0,0 +1,15 @@
use diesel::r2d2::{ConnectionManager, Pool, PoolError, PooledConnection};
use diesel::MysqlConnection;
pub type DbPool = r2d2::Pool<ConnectionManager<MysqlConnection>>;
pub type MyPooledConnection = PooledConnection<ConnectionManager<MysqlConnection>>;
fn init_pool(database_url: &str) -> Result<DbPool, PoolError> {
let manager = ConnectionManager::<MysqlConnection>::new(database_url);
Pool::builder().build(manager)
}
pub fn get_pool() -> DbPool {
let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL");
init_pool(&connspec).expect("Failed to create DB pool")
}