Refactored to remove from Database refferences.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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<()> {
|
||||
|
||||
Reference in New Issue
Block a user