feat(infrastructure): implement SQLite repository for relay labels
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)
This commit is contained in:
33
backend/src/infrastructure/persistence/entities/mod.rs
Normal file
33
backend/src/infrastructure/persistence/entities/mod.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
//! Infrastructure entities for database persistence.
|
||||
//!
|
||||
//! This module defines entities that directly map to database tables,
|
||||
//! providing a clear separation between the persistence layer and the
|
||||
//! domain layer. These entities represent raw database records without
|
||||
//! domain validation or business logic.
|
||||
//!
|
||||
//! # Conversion Pattern
|
||||
//!
|
||||
//! Infrastructure entities implement `TryFrom` traits to convert between
|
||||
//! database records and domain types:
|
||||
//!
|
||||
//! ```rust
|
||||
//! # use sta::domain::relay::types::{RelayId, RelayLabel};
|
||||
//! # use sta::infrastructure::persistence::entities::relay_label_record::RelayLabelRecord;
|
||||
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
//! // Database Record -> Domain Types
|
||||
//! // ... from database
|
||||
//! let record: RelayLabelRecord = RelayLabelRecord { relay_id: 2, label: "label".to_string() };
|
||||
//! let (relay_id, relay_label): (RelayId, RelayLabel) = record.try_into()?;
|
||||
//!
|
||||
//! // Domain Types -> Database Record
|
||||
//! let domain_record= RelayLabelRecord::new(relay_id, &relay_label);
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
/// Database entity for relay labels.
|
||||
///
|
||||
/// This module contains the `RelayLabelRecord` struct which represents
|
||||
/// a single row in the `RelayLabels` database table, along with conversion
|
||||
/// traits to and from domain types.
|
||||
pub mod relay_label_record;
|
||||
Reference in New Issue
Block a user