Refactored the whole code to a better structure
This commit is contained in:
parent
87cc8ac794
commit
12b865bf17
21 changed files with 473 additions and 257 deletions
15
project/src/db_connection.rs
Normal file
15
project/src/db_connection.rs
Normal 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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue