adapter-sqlite: all repo implementations + wire fn + migrations copy

This commit is contained in:
2026-07-12 02:34:12 +02:00
parent 1428f264bb
commit e8179d1f53
29 changed files with 1987 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
//! SQLite adapter for app settings (AppSettingsRepository).
use async_trait::async_trait;
use sqlx::SqlitePool;
use domain::{
ports::settings::AppSettingsRepository,
DomainError, DomainResult,
};
pub struct SqliteAppSettings {
pool: SqlitePool,
}
impl SqliteAppSettings {
pub fn new(pool: SqlitePool) -> Self {
Self { pool }
}
}
#[async_trait]
impl AppSettingsRepository for SqliteAppSettings {
async fn get(&self, key: &str) -> DomainResult<Option<String>> {
sqlx::query_scalar::<_, String>("SELECT value FROM app_settings WHERE key = ?")
.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 OR REPLACE INTO app_settings (key, value) VALUES (?, ?)")
.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()))
}
}