Module sql_interface_data

Source
Expand description

Contains functions for execution of all queries relevant for time-data recording (recorder) Manages all database interactions for time-series sensor and state data.

This module provides a dedicated interface, SqlInterfaceData, for handling all SQL operations related to the main data table. It encapsulates the logic for writing RecorderDataFrame objects, which contain a snapshot of all sensor readings and system states at a specific point in time.

§Key Components

  • SqlInterfaceData Struct: The primary struct that holds a database connection and provides methods for all data-logging database operations.

  • new() Constructor: A critical entry point that not only creates an SqlInterfaceData instance but also performs essential “fail-fast” validation. At initialization, it checks whether the number of rows in the data table exceeds the max_rows_data limit defined in the application configuration. This acts as a safeguard against uncontrolled table size at startup.

  • write_data_frame_to_database(): The core function of this module. It takes a RecorderDataFrame and constructs a single INSERT ... ON DUPLICATE KEY UPDATE query. It intelligently handles optional or invalid floating-point values (e.g., None, NaN, Infinity) by converting them to NULL before insertion, ensuring data integrity in the database.

§Design and Purpose

The main goal of this module is to provide a robust and encapsulated interface for persisting the application’s high-frequency time-series data.

  • Encapsulation: All SQL logic specific to the data table is contained within this module, separating concerns and simplifying the data logger’s responsibilities.

  • Data Integrity: The constructor’s validation logic enforces the configured row limit at startup. The write_data_frame_to_database function ensures that invalid or missing data points are correctly stored as NULL in the database, preventing data corruption.

Structs§

SqlInterfaceData
Contains the configuration and the implementation of the SQL interface for time-based data.