Refactored to remove from Database refferences.

This commit is contained in:
Jordan Petridis
2017-11-19 23:32:37 +02:00
parent beaeeffba8
commit 5ad52fa4b2
8 changed files with 91 additions and 125 deletions
+3 -3
View File
@@ -90,11 +90,11 @@ fn get_temp_db() -> TempDB {
let tmp_dir = tempdir::TempDir::new("hammond_unit_test").unwrap();
let db_path = tmp_dir
.path()
.join(format!("hammonddb_{}.db", rng.gen::<usize>()));
.join("test.db");
let pool = utils::init_pool(db_path.to_str().unwrap());
let db = pool.get().unwrap();
utils::run_migration_on(&db).unwrap();
let db = pool.clone().get().unwrap();
utils::run_migration_on(&*db).unwrap();
TempDB(tmp_dir, db_path, pool)
}
+3 -1
View File
@@ -27,7 +27,9 @@ pub fn init() -> Result<()> {
pub fn init_pool(db_path: &str) -> Pool {
let config = r2d2::Config::default();
let manager = ConnectionManager::<SqliteConnection>::new(db_path);
r2d2::Pool::new(config, manager).expect("Failed to create pool.")
let pool = r2d2::Pool::new(config, manager).expect("Failed to create pool.");
info!("Database pool initialized.");
pool
}
pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {