Expand description
Contains functions for execution of all queries relevant for refill (water) Manages all database interactions for the automated water refill system.
This module provides a dedicated interface, SqlInterfaceRefill, for handling
all SQL operations related to the refill event log (refill table). It also
defines a DatabaseInterfaceRefillTrait to decouple the core refill logic
from the specific database implementation, adhering to the Dependency Inversion Principle.
§Key Components
-
DatabaseInterfaceRefillTrait: An abstraction that defines the contract for any component that interacts with refill data. This is crucial for testability, as it allows for mock implementations to be used in unit tests without needing a live database. -
SqlInterfaceRefillStruct: The concrete implementation of the trait, holding a database connection and providing methods for all refill-related operations. -
new()Constructor: A critical entry point that performs “fail-fast” validation at initialization. It checks whether the number of rows in therefilltable exceeds themax_rows_refilllimit defined in the application configuration, preventing uncontrolled table growth. -
Statistics Methods: Functions like
get_refill_count_of_last_24handget_refill_volume_of_last_24hprovide aggregated data about recent refill activity. -
insert_refill_event(): The core logging function that persists the details of a completed refill operation to the database.
§Design and Purpose
The main goal of this module is to provide a robust, encapsulated, and testable interface for the refill subsystem’s data.
-
Encapsulation: All SQL queries and logic specific to the
refilltable are contained within this module, separating concerns. -
Data Integrity: The constructor’s validation logic enforces the configured row limit at startup, ensuring the system doesn’t start with an overgrown log table.
-
Abstraction for Testability: The
DatabaseInterfaceRefillTraitallows higher-level components to be tested independently of the database.
Structs§
- SqlInterface
Refill - Contains the configuration and the implementation of the SQL interface for Refill.
Traits§
- Database
Interface Refill Trait - Trait for interfacing between refill and SQL database This trait is prerequisite to use mock implementation for testing