adapter-sqlite: all repo implementations + wire fn + migrations copy
This commit is contained in:
40
crates/adapters/sqlite/src/transcode.rs
Normal file
40
crates/adapters/sqlite/src/transcode.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
//! SQLite adapter for transcode settings (TranscodeSettingsRepository).
|
||||
|
||||
use async_trait::async_trait;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use domain::{
|
||||
ports::transcode::TranscodeSettingsRepository,
|
||||
DomainError, DomainResult,
|
||||
};
|
||||
|
||||
pub struct SqliteTranscodeSettings {
|
||||
pool: SqlitePool,
|
||||
}
|
||||
|
||||
impl SqliteTranscodeSettings {
|
||||
pub fn new(pool: SqlitePool) -> Self {
|
||||
Self { pool }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl TranscodeSettingsRepository for SqliteTranscodeSettings {
|
||||
async fn load_cleanup_ttl(&self) -> DomainResult<Option<u32>> {
|
||||
let row: Option<(i64,)> =
|
||||
sqlx::query_as("SELECT cleanup_ttl_hours FROM transcode_settings WHERE id = 1")
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.map_err(|e| DomainError::InfrastructureError(e.to_string()))?;
|
||||
Ok(row.map(|(h,)| h as u32))
|
||||
}
|
||||
|
||||
async fn save_cleanup_ttl(&self, hours: u32) -> DomainResult<()> {
|
||||
sqlx::query("UPDATE transcode_settings SET cleanup_ttl_hours = ? WHERE id = 1")
|
||||
.bind(hours as i64)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_err(|e| DomainError::InfrastructureError(e.to_string()))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user