Private
Public Access
1
0

refactor: with_repository/with_settings

This commit is contained in:
2025-04-25 16:34:00 -07:00
parent 89c9ffc187
commit b1f171136a
5 changed files with 249 additions and 227 deletions

View File

@@ -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)
}
}