pub struct SqlInterfaceData {
pub conn: PooledConn,
}Expand description
Contains the configuration and the implementation of the SQL interface for time-based data.
Fields§
§conn: PooledConnConnection to the database
Implementations§
Source§impl SqlInterfaceData
impl SqlInterfaceData
Sourcepub fn new(
conn: PooledConn,
max_rows_data: u64,
) -> Result<SqlInterfaceData, SqlInterfaceError>
pub fn new( conn: PooledConn, max_rows_data: u64, ) -> Result<SqlInterfaceData, SqlInterfaceError>
Creates a new SqlInterfaceData instance.
This constructor initializes the time-based data SQL interface with an
established database connection. It performs a pre-flight check to ensure
the number of rows in the data table does not exceed the configured limit.
§Arguments
conn- An active, pooled database connection.max_rows_data- The maximum allowed number of rows in thedatatable. If0, the check is skipped.
§Returns
A Result containing a new SqlInterfaceData instance on success.
§Errors
This function will return an error if:
- The initial database query to get the table row count fails (
DatabaseCheckDataFailure). - The retrieved row count is a negative number, indicating a database issue (
DatabaseDataTableNegativeValue). - The number of rows in the
datatable exceeds the configuredmax_rows_datalimit (DatabaseDataTableContainsTooManyRows).
Sourcepub fn write_data_frame_to_database(
&mut self,
data: &RecorderDataFrame,
) -> Result<(), SqlInterfaceError>
pub fn write_data_frame_to_database( &mut self, data: &RecorderDataFrame, ) -> Result<(), SqlInterfaceError>
Writes a complete RecorderDataFrame to the SQL database.
This function processes all data points within the provided RecorderDataFrame.
It intelligently handles optional (Option<f32>) and floating-point values
(f32) by converting None, NaN (Not-a-Number), or infinite values
into NULL for database insertion. Boolean options are similarly converted
to NULL if None.
The data is inserted into the database. If a record with the same timestamp
already exists, the existing record will be updated (this behavior depends
on the underlying SQL query SQL_QUERY_WRITE_DATA using an
ON DUPLICATE KEY UPDATE clause).
§Arguments
data- A reference to theRecorderDataFramecontaining the data to be written.
§Returns
An empty Result (Ok(())) if the data frame was successfully inserted or updated in the database.
§Errors
Returns SqlInterfaceError::InsertDataFrameFailure if the database operation fails.
This can be caused by a lost connection, constraint violations (e.g., foreign keys),
incorrect data types, or a malformed SQL query. The original mysql::Error is
included as the source for detailed debugging.