Module sql_interface_balling

Source
Expand description

Contains functions for execution of all queries relevant for Balling mineral dosing Manages all database interactions for the Balling dosing system.

This module provides a dedicated interface, SqlInterfaceBalling, for handling all SQL operations related to the Balling feature. It encapsulates logic for reading pump configurations (ballingsetvals), logging dosing events (ballingdosinglog), and retrieving dosing history.

§Key Components

  • SqlInterfaceBalling Struct: The primary struct that holds a database connection and provides methods for all Balling-related database operations.

  • BallingSetVal Struct: A data structure representing the configuration parameters for a single Balling pump, such as dosing speed and volume.

  • new() Constructor: A critical entry point that not only creates an SqlInterfaceBalling instance but also performs essential “fail-fast” validation. At initialization, it checks the database for:

    • The presence of NULL values in the configuration table.
    • Whether the number of rows in the ballingsetvals and ballingdosinglog tables exceeds the limits defined in the application configuration. This ensures the system doesn’t start in an invalid or inconsistent state.

§Design and Purpose

The main goal of this module is to provide a robust, encapsulated, and safe interface for the Balling subsystem’s data.

  • Encapsulation: All SQL queries and logic specific to Balling are contained within this module, separating concerns and making the overall database architecture cleaner.

  • Data Integrity: The constructor’s validation logic enforces data integrity rules at startup, preventing runtime errors caused by misconfigured or overgrown database tables.

Structs§

BallingSetVal
Contains set value data for each pump.
SqlInterfaceBalling
Contains the configuration and the implementation of the SQL interface for Balling.