use domain::{DataSource, DataSourceId}; use crate::SqliteConfigStore; use crate::error::SqliteConfigError; use crate::serialization::data_source as ser; impl SqliteConfigStore { pub(crate) async fn get_data_source_impl(&self, id: DataSourceId) -> Result, SqliteConfigError> { let row = sqlx::query("SELECT * FROM data_sources WHERE id = ?") .bind(id as i64) .fetch_optional(&self.pool) .await .map_err(SqliteConfigError::Sql)?; match row { None => Ok(None), Some(row) => Ok(Some(ser::data_source_from_row(&row)?)), } } pub(crate) async fn list_data_sources_impl(&self) -> Result, SqliteConfigError> { let rows = sqlx::query("SELECT * FROM data_sources") .fetch_all(&self.pool) .await .map_err(SqliteConfigError::Sql)?; rows.iter().map(|r| ser::data_source_from_row(r)).collect() } pub(crate) async fn save_data_source_impl(&self, source: &DataSource) -> Result<(), SqliteConfigError> { let config_json = ser::data_source_config_to_json(&source.config)?; let type_str = ser::data_source_type_to_str(&source.source_type); sqlx::query( "INSERT OR REPLACE INTO data_sources (id, name, source_type, poll_interval_secs, config) VALUES (?, ?, ?, ?, ?)" ) .bind(source.id as i64) .bind(&source.name) .bind(type_str) .bind(source.poll_interval.as_secs() as i64) .bind(&config_json) .execute(&self.pool) .await .map_err(SqliteConfigError::Sql)?; Ok(()) } pub(crate) async fn delete_data_source_impl(&self, id: DataSourceId) -> Result<(), SqliteConfigError> { sqlx::query("DELETE FROM data_sources WHERE id = ?") .bind(id as i64) .execute(&self.pool) .await .map_err(SqliteConfigError::Sql)?; Ok(()) } }