- 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
91 lines
2.8 KiB
Rust
91 lines
2.8 KiB
Rust
use async_trait::async_trait;
|
|
use sqlx::SqlitePool;
|
|
|
|
use adapter_common::map_sqlx_error;
|
|
use domain::{
|
|
ports::provider_config::{ProviderConfigCommand, ProviderConfigQuery},
|
|
DomainResult, ProviderConfigRow,
|
|
};
|
|
|
|
pub struct SqliteProviderConfig {
|
|
pool: SqlitePool,
|
|
}
|
|
|
|
impl SqliteProviderConfig {
|
|
pub fn new(pool: SqlitePool) -> Self {
|
|
Self { pool }
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl ProviderConfigCommand for SqliteProviderConfig {
|
|
async fn upsert(&self, row: &ProviderConfigRow) -> DomainResult<()> {
|
|
sqlx::query(
|
|
r#"INSERT INTO provider_configs (id, provider_type, config_json, enabled, updated_at)
|
|
VALUES (?, ?, ?, ?, ?)
|
|
ON CONFLICT(id) DO UPDATE SET
|
|
provider_type = excluded.provider_type,
|
|
config_json = excluded.config_json,
|
|
enabled = excluded.enabled,
|
|
updated_at = excluded.updated_at"#,
|
|
)
|
|
.bind(row.id())
|
|
.bind(row.provider_type())
|
|
.bind(row.config_json())
|
|
.bind(row.enabled() as i64)
|
|
.bind(row.updated_at())
|
|
.execute(&self.pool)
|
|
.await
|
|
.map_err(map_sqlx_error)?;
|
|
Ok(())
|
|
}
|
|
|
|
async fn delete(&self, id: &str) -> DomainResult<()> {
|
|
sqlx::query("DELETE FROM provider_configs WHERE id = ?")
|
|
.bind(id)
|
|
.execute(&self.pool)
|
|
.await
|
|
.map_err(map_sqlx_error)?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl ProviderConfigQuery for SqliteProviderConfig {
|
|
async fn get_all(&self) -> DomainResult<Vec<ProviderConfigRow>> {
|
|
let rows: Vec<(String, String, String, i64, String)> = sqlx::query_as(
|
|
"SELECT id, provider_type, config_json, enabled, updated_at FROM provider_configs",
|
|
)
|
|
.fetch_all(&self.pool)
|
|
.await
|
|
.map_err(map_sqlx_error)?;
|
|
|
|
Ok(rows
|
|
.into_iter()
|
|
.map(|(id, provider_type, config_json, enabled, updated_at)| {
|
|
ProviderConfigRow::from_persistence(
|
|
id,
|
|
provider_type,
|
|
config_json,
|
|
enabled != 0,
|
|
updated_at,
|
|
)
|
|
})
|
|
.collect())
|
|
}
|
|
|
|
async fn get_by_id(&self, id: &str) -> DomainResult<Option<ProviderConfigRow>> {
|
|
let row: Option<(String, String, String, i64, String)> = sqlx::query_as(
|
|
"SELECT id, provider_type, config_json, enabled, updated_at FROM provider_configs WHERE id = ?",
|
|
)
|
|
.bind(id)
|
|
.fetch_optional(&self.pool)
|
|
.await
|
|
.map_err(map_sqlx_error)?;
|
|
|
|
Ok(row.map(|(id, provider_type, config_json, enabled, updated_at)| {
|
|
ProviderConfigRow::from_persistence(id, provider_type, config_json, enabled != 0, updated_at)
|
|
}))
|
|
}
|
|
}
|