Struct SqlInterfaceSchedule

Source
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: PooledConn

Connection to the database

§schedules: Vec<ScheduleEntry>

Result of the post-processed SQL query

Implementations§

Source§

impl SqlInterfaceSchedule

Source

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 the schedule table.
§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 schedule table contains entries with NULL values (DatabaseScheduleTableContainsNull).
  • The number of rows in the schedule table exceeds max_rows_schedule (DatabaseScheduleTableContainsTooManyRows).
Source

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.
Source

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 - The ScheduleType to 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.

Trait Implementations§

Source§

impl Debug for SqlInterfaceSchedule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Pingable for SqlInterfaceSchedule

Source§

fn ping(&mut self)

Pings the database to check connection health and prevent timeouts.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T