refactor: with_repository/with_settings
This commit is contained in:
@@ -8,7 +8,7 @@ use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
|
||||
|
||||
pub struct Database {
|
||||
pub connection: SqliteConnection,
|
||||
connection: SqliteConnection,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
@@ -24,11 +24,19 @@ impl Database {
|
||||
Self::new(":memory:")
|
||||
}
|
||||
|
||||
pub fn get_repository(&mut self) -> Repository {
|
||||
Repository::new(self)
|
||||
pub fn with_repository<F, R>(&mut self, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&mut Repository) -> R,
|
||||
{
|
||||
let mut repository = Repository::new(&mut self.connection);
|
||||
f(&mut repository)
|
||||
}
|
||||
|
||||
pub fn get_settings(&mut self) -> Settings {
|
||||
Settings::new(self)
|
||||
pub fn with_settings<F, R>(&mut self, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&mut Settings) -> R,
|
||||
{
|
||||
let mut settings = Settings::new(&mut self.connection);
|
||||
f(&mut settings)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user