adapter-sqlite: all repo implementations + wire fn + migrations copy
This commit is contained in:
78
crates/adapters/sqlite/src/wire.rs
Normal file
78
crates/adapters/sqlite/src/wire.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
//! Wiring function that instantiates all SQLite repositories and returns them
|
||||
//! as trait-object Arcs.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use domain::ports::{
|
||||
activity::{ActivityLogCommand, ActivityLogQuery},
|
||||
channel::{ChannelCommand, ChannelQuery},
|
||||
library::{LibraryCommand, LibraryQuery},
|
||||
provider_config::{ProviderConfigCommand, ProviderConfigQuery},
|
||||
schedule::{ScheduleCommand, ScheduleQuery},
|
||||
settings::AppSettingsRepository,
|
||||
transcode::TranscodeSettingsRepository,
|
||||
user::{UserCommand, UserQuery},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
activity::SqliteActivityLog,
|
||||
channel::SqliteChannelRepository,
|
||||
library::SqliteLibraryRepository,
|
||||
provider_config::SqliteProviderConfig,
|
||||
schedule::SqliteScheduleRepository,
|
||||
settings::SqliteAppSettings,
|
||||
transcode::SqliteTranscodeSettings,
|
||||
user::SqliteUserRepository,
|
||||
};
|
||||
|
||||
/// All SQLite adapter outputs, ready to be injected into the application layer.
|
||||
pub struct SqliteWireOutput {
|
||||
pub user_command: Arc<dyn UserCommand>,
|
||||
pub user_query: Arc<dyn UserQuery>,
|
||||
pub channel_command: Arc<dyn ChannelCommand>,
|
||||
pub channel_query: Arc<dyn ChannelQuery>,
|
||||
pub schedule_command: Arc<dyn ScheduleCommand>,
|
||||
pub schedule_query: Arc<dyn ScheduleQuery>,
|
||||
pub library_command: Arc<dyn LibraryCommand>,
|
||||
pub library_query: Arc<dyn LibraryQuery>,
|
||||
pub activity_command: Arc<dyn ActivityLogCommand>,
|
||||
pub activity_query: Arc<dyn ActivityLogQuery>,
|
||||
pub settings: Arc<dyn AppSettingsRepository>,
|
||||
pub provider_config_command: Arc<dyn ProviderConfigCommand>,
|
||||
pub provider_config_query: Arc<dyn ProviderConfigQuery>,
|
||||
pub transcode_settings: Arc<dyn TranscodeSettingsRepository>,
|
||||
}
|
||||
|
||||
/// Create all SQLite repository implementations from a single pool.
|
||||
///
|
||||
/// Each struct wraps a clone of the same pool. Repositories that implement
|
||||
/// both Command and Query traits share a single `Arc` via `.clone()`.
|
||||
pub fn wire(pool: SqlitePool) -> SqliteWireOutput {
|
||||
let user = Arc::new(SqliteUserRepository::new(pool.clone()));
|
||||
let channel = Arc::new(SqliteChannelRepository::new(pool.clone()));
|
||||
let schedule = Arc::new(SqliteScheduleRepository::new(pool.clone()));
|
||||
let library = Arc::new(SqliteLibraryRepository::new(pool.clone()));
|
||||
let activity = Arc::new(SqliteActivityLog::new(pool.clone()));
|
||||
let settings = Arc::new(SqliteAppSettings::new(pool.clone()));
|
||||
let provider_config = Arc::new(SqliteProviderConfig::new(pool.clone()));
|
||||
let transcode_settings = Arc::new(SqliteTranscodeSettings::new(pool));
|
||||
|
||||
SqliteWireOutput {
|
||||
user_command: user.clone(),
|
||||
user_query: user,
|
||||
channel_command: channel.clone(),
|
||||
channel_query: channel,
|
||||
schedule_command: schedule.clone(),
|
||||
schedule_query: schedule,
|
||||
library_command: library.clone(),
|
||||
library_query: library,
|
||||
activity_command: activity.clone(),
|
||||
activity_query: activity,
|
||||
settings,
|
||||
provider_config_command: provider_config.clone(),
|
||||
provider_config_query: provider_config,
|
||||
transcode_settings,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user