pub struct SqlInterfaceSchedule {
pub conn: PooledConn,
schedules: Vec<ScheduleEntry>,
}Expand description
Contains the configuration and the implementation of the SQL interface for Schedule.
Fields§
§conn: PooledConnConnection to the database
schedules: Vec<ScheduleEntry>Result of the post-processed SQL query
Implementations§
Source§impl SqlInterfaceSchedule
impl SqlInterfaceSchedule
Sourcepub fn new(
conn: PooledConn,
max_rows_schedule: u64,
) -> Result<SqlInterfaceSchedule, SqlInterfaceError>
pub fn new( conn: PooledConn, max_rows_schedule: u64, ) -> Result<SqlInterfaceSchedule, SqlInterfaceError>
Creates a new SqlInterfaceSchedule instance.
This constructor initializes the interface with a database connection. It performs
several pre-flight checks to ensure data integrity, such as verifying that the
schedule table contains no NULL values and that its row count is within the
configured limit.
§Arguments
conn- An active, pooled database connection.max_rows_schedule- The maximum allowed number of rows in thescheduletable.
§Returns
A Result containing a new SqlInterfaceSchedule instance on success.
§Errors
This function will return an error if:
- Any of the initial database queries to get table counts fail (
DatabaseCheckScheduleFailure). - Any of the retrieved counts are negative, indicating a database issue (
DatabaseScheduleTableNegativeValue). - The
scheduletable contains entries withNULLvalues (DatabaseScheduleTableContainsNull). - The number of rows in the
scheduletable exceedsmax_rows_schedule(DatabaseScheduleTableContainsTooManyRows).
Sourcepub fn read_schedule(&mut self) -> Result<(), Vec<SqlInterfaceError>>
pub fn read_schedule(&mut self) -> Result<(), Vec<SqlInterfaceError>>
Reads all schedule entries from the SQL database, processing and storing them internally.
This function queries the database for all available schedule configurations.
It then attempts to convert each raw database entry into a ScheduleEntry struct.
The internal schedules vector is cleared and then populated with only the
successfully processed entries.
§Returns
Ok(()): If the database query was successful and all retrieved entries were processed without errors.
§Errors
Returns a Vec<SqlInterfaceError> which will contain one or more errors if:
- The initial database query fails (
ScheduleRequestFailure). - One or more raw schedule entries fail to be converted into a
ScheduleEntry(ScheduleProcessingFailure). This can happen due to invalid data formats (e.g., a malformed time string) in the database.
Sourcepub fn find_schedule(
&self,
schedule_type: ScheduleType,
) -> Result<&ScheduleEntry, SqlInterfaceError>
pub fn find_schedule( &self, schedule_type: ScheduleType, ) -> Result<&ScheduleEntry, SqlInterfaceError>
Finds a specific schedule entry by its type from the internal cache.
This function searches the schedules vector, which must be populated by
a prior call to read_schedule, for an entry matching the given schedule_type.
§Arguments
schedule_type- TheScheduleTypeto search for.
§Returns
A Result containing a reference to the found ScheduleEntry on success.
§Errors
Returns SqlInterfaceError::ScheduleTypeNotFound if no schedule entry
matching the provided schedule_type exists in the internal cache.