- strip all comments except WHY workaround notes (3 remain) - remove all #[allow(dead_code)]; fix via _prefix rename - extract named constants: JWT time units, token types, default config values, jellyfin fallback bitrate - DRY: move serialize_enum_as_string, content_type_str, parse_content_type, parse_genres_blob to adapter-common - sqlite+postgres library.rs use shared helpers instead of local copies - sqlite+postgres channel.rs use shared serialize_enum_as_string - remove dead `let _ = ext` in scanner.rs
49 lines
1.4 KiB
Rust
49 lines
1.4 KiB
Rust
use async_trait::async_trait;
|
|
use sqlx::PgPool;
|
|
|
|
use domain::{
|
|
ports::settings::AppSettingsRepository,
|
|
DomainError, DomainResult,
|
|
};
|
|
|
|
pub struct PgAppSettings {
|
|
pool: PgPool,
|
|
}
|
|
|
|
impl PgAppSettings {
|
|
pub fn new(pool: PgPool) -> Self {
|
|
Self { pool }
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl AppSettingsRepository for PgAppSettings {
|
|
async fn get(&self, key: &str) -> DomainResult<Option<String>> {
|
|
sqlx::query_scalar::<_, String>("SELECT value FROM app_settings WHERE key = $1")
|
|
.bind(key)
|
|
.fetch_optional(&self.pool)
|
|
.await
|
|
.map_err(|e| DomainError::InfrastructureError(e.to_string()))
|
|
}
|
|
|
|
async fn set(&self, key: &str, value: &str) -> DomainResult<()> {
|
|
sqlx::query(
|
|
"INSERT INTO app_settings (key, value) VALUES ($1, $2)
|
|
ON CONFLICT(key) DO UPDATE SET value = EXCLUDED.value",
|
|
)
|
|
.bind(key)
|
|
.bind(value)
|
|
.execute(&self.pool)
|
|
.await
|
|
.map(|_| ())
|
|
.map_err(|e| DomainError::InfrastructureError(e.to_string()))
|
|
}
|
|
|
|
async fn get_all(&self) -> DomainResult<Vec<(String, String)>> {
|
|
sqlx::query_as::<_, (String, String)>("SELECT key, value FROM app_settings ORDER BY key")
|
|
.fetch_all(&self.pool)
|
|
.await
|
|
.map_err(|e| DomainError::InfrastructureError(e.to_string()))
|
|
}
|
|
}
|