Add complete SQLite implementation of RelayLabelRepository trait with all CRUD operations (get_label, save_label, delete_label, get_all_labels). Key changes: - Create infrastructure entities module with RelayLabelRecord struct - Implement TryFrom traits for converting between database records and domain types - Add From<sqlx::Error> and From<RelayLabelError> for RepositoryError - Write comprehensive functional tests covering all repository operations - Verify proper handling of edge cases (empty results, overwrites, max length) TDD phase: GREEN - All repository trait tests now passing with SQLite implementation Ref: T036 (specs/001-modbus-relay-control/tasks.md)
31 lines
882 B
Rust
31 lines
882 B
Rust
mod label;
|
|
pub use label::RelayLabelRepository;
|
|
|
|
use super::types::{RelayId, RelayLabelError};
|
|
|
|
/// Errors that can occur during repository operations.
|
|
///
|
|
/// This enum provides structured error handling for all data persistence
|
|
/// operations related to relay management.
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum RepositoryError {
|
|
/// A database operation failed with the given error message.
|
|
#[error("Database error: {0}")]
|
|
DatabaseError(String),
|
|
/// The requested relay was not found in the repository.
|
|
#[error("Relay not found: {0}")]
|
|
NotFound(RelayId),
|
|
}
|
|
|
|
impl From<sqlx::Error> for RepositoryError {
|
|
fn from(value: sqlx::Error) -> Self {
|
|
Self::DatabaseError(value.to_string())
|
|
}
|
|
}
|
|
|
|
impl From<RelayLabelError> for RepositoryError {
|
|
fn from(value: RelayLabelError) -> Self {
|
|
Self::DatabaseError(value.to_string())
|
|
}
|
|
}
|