Struct SqlInterfaceFeed

Source
pub struct SqlInterfaceFeed {
    pub conn: PooledConn,
}
Expand description

Contains the configuration and the implementation of the SQL interface for Feed.

Fields§

§conn: PooledConn

connection to SQL database

Implementations§

Source§

impl SqlInterfaceFeed

Source

pub fn new( conn: PooledConn, max_rows_feed_pattern: u64, max_rows_feed_schedule: u64, max_rows_feed_log: u64, ) -> Result<Self, SqlInterfaceError>

Creates a new SqlInterfaceFeed instance.

This constructor initializes the feed management SQL interface with an established database connection. It performs several pre-flight checks to ensure data integrity and adherence to configured limits, such as verifying that tables contain no NULL values and that row counts are within their specified maximums.

§Arguments
  • conn - An active, pooled database connection.
  • max_rows_feed_pattern - The maximum allowed rows in the feedpatterns table.
  • max_rows_feed_schedule - The maximum allowed rows in the feedschedule table.
  • max_rows_feed_log - The maximum allowed rows in the feedlog table.
§Returns

A Result containing a new SqlInterfaceFeed instance on success.

§Errors

This function will return an error if:

  • Any of the initial database queries to get table counts or check for NULLs fail (DatabaseCheckFeedSetValsFailure).
  • Any of the retrieved counts are negative, indicating a database issue (DatabaseFeedTableNegativeValue).
  • The feedpatterns or feedschedule tables contain entries with NULL values (DatabaseFeedSetValTableContainsNull).
  • The number of rows in any of the checked tables exceeds its configured maximum (DatabaseFeedTableContainsTooManyRows). .
Source

pub(crate) fn get_feedschedule_entries_from_database( &mut self, sql_query: &str, ) -> Result<Option<Vec<FeedScheduleEntry>>, SqlInterfaceError>

Retrieves and post-processes feed schedule entries from the database based on a given SQL query.

This private helper function executes the provided sql_query to fetch raw schedule data. It then attempts to convert these raw SqlScheduleEntry records into fully typed FeedScheduleEntry structs.

§Arguments
  • sql_query - The SQL query string used to retrieve feed schedule entries.
§Returns

A Result containing an Option<Vec<FeedScheduleEntry>>:

  • Ok(Some(Vec<FeedScheduleEntry>)): If one or more schedule entries are successfully retrieved and converted.
  • Ok(None): If the query returns no rows.
§Errors

This function will return an error if:

  • The underlying database query fails (FeedScheduleEntryRequestFailure). This can be due to a connection issue or an invalid query.
  • The query returns results, but one of the entries cannot be processed (e.g., due to a malformed timestamp), resulting in FeedScheduleEntryTimeStampProcessingFailure.
Source

pub fn get_feedpattern_header_from_database( &mut self, profile_id: i32, ) -> Result<SqlFeedpatternHeader, SqlInterfaceError>

Retrieves the header (basic information) of a specific feed pattern from the database.

This function queries the database using the provided profile_id to fetch the feed pattern’s unique ID and its associated name. It strictly expects exactly one matching header entry.

§Arguments
  • profile_id - The unique identifier of the feed profile whose header is to be retrieved.
§Returns

A Result which is:

  • Ok(SqlFeedpatternHeader) if exactly one matching header entry is found.
  • Err(SqlInterfaceError::SingleFeedpatternRequestFailure) if the database query fails.
  • Err(SqlInterfaceError::SingleFeedpatternRequestNoSingleResponse) if the query returns no entry or more than one entry for the given profile_id.
Source

pub fn get_feed_phase_from_database( &mut self, profile_id: i32, phase_nr: i32, ) -> Result<SqlFeedPhase, SqlInterfaceError>

Retrieves the specific data for a single phase of a feed pattern from the database.

This function constructs a query using both the profile_id and the phase_nr to fetch the detailed configuration for that particular feed phase. It strictly expects to find exactly one matching phase entry.

§Arguments
  • profile_id - The unique identifier of the feed profile.
  • phase_nr - The specific phase number (e.g., 1, 2, …, 10) within the feed profile.
§Returns

A Result which is:

  • Ok(SqlFeedPhase) if exactly one matching phase entry is found for the given profile and phase number.
  • Err(SqlInterfaceError::SingleFeedpatternRequestFailure) if the database query fails.
  • Err(SqlInterfaceError::SingleFeedpatternRequestNoSingleResponse) if the query returns no entry or more than one entry for the specified profile and phase.

Trait Implementations§

Source§

impl DatabaseInterfaceFeedTrait for SqlInterfaceFeed

Source§

fn get_current_timestamp(&mut self) -> Result<NaiveDateTime, SqlInterfaceError>

Retrieves the current timestamp from the database using the internal connection.

This function acts as a proxy, calling the general SqlInterface::get_current_timestamp method with the SqlInterfaceFeed’s established database connection.

§Returns

A Result which is:

  • Ok(NaiveDateTime): The current timestamp as reported by the database.
  • Err(SqlInterfaceError): If any error occurs during the retrieval or parsing of the timestamp from the database.
Source§

fn get_past_feedschedule_entries_from_database( &mut self, ) -> Result<Option<Vec<FeedScheduleEntry>>, SqlInterfaceError>

Retrieves feed schedule entries from the database that are scheduled in the past.

This function queries the database for all feed schedule entries whose timestamps are before the current time. The raw database entries are then post-processed into FeedScheduleEntry structs.

§Returns

A Result which is:

  • Ok(Some(Vec<FeedScheduleEntry>)) if one or more past feed schedule entries are found.
  • Ok(None) if no past feed schedule entries are found in the database.
  • Err(SqlInterfaceError) if any error occurs during the database query or during the conversion of raw database data into FeedScheduleEntry structs.
Source§

fn insert_feed_event( &mut self, timestamp: NaiveDateTime, feeder_run_time: f64, profile_name: String, profile_id: i32, ) -> Result<(), SqlInterfaceError>

Inserts a new feed event record into the database.

This function logs details about a completed feed operation, including the timestamp, how long the feeder ran, and which feed profile was used.

§Arguments
  • timestamp - The NaiveDateTime when the feed event occurred.
  • feeder_run_time - The duration (in seconds) the feeder motor was active.
  • profile_name - The name of the feed profile that was executed for this event.
  • profile_id - The unique identifier of the feed profile that was executed.
§Returns

An empty Result (Ok(())) if the feed event record was successfully inserted.

§Errors

Returns SqlInterfaceError::InsertFeedEventFailure if the INSERT query fails. This can happen due to a lost connection, constraint violation (e.g., foreign key), or incorrect data types. The original mysql::Error is included as the source.

Source§

fn get_single_feedpattern_from_database( &mut self, profile_id: i32, ) -> Result<Feedpattern, SqlInterfaceError>

Retrieves a complete Feedpattern from the SQL database, including its header and all associated phases.

This function first fetches the header information for the specified profile_id. It then retrieves data for each of the 10 expected feed phases, converting raw database flags into booleans.

§Arguments
  • profile_id - The unique identifier of the feed profile to retrieve.
§Returns

A Result containing a fully constructed Feedpattern object on success.

§Errors

This function will return an error if:

  • The query for the feed pattern header fails, the header is not found, or multiple headers are found.
  • The query for any of the 10 feed phases fails, a phase is not found, or multiple phases are found.
  • A retrieved feed phase contains an invalid (negative) duration value.
Source§

fn update_feedschedule_entries_in_database( &mut self, feedschedule_entries: &mut Vec<FeedScheduleEntry>, ) -> Result<(), SqlInterfaceError>

Updates or deletes multiple feed schedule entries in the database.

This function iterates through a list of FeedScheduleEntry structs. For each entry:

  • If repeat_daily is true, it updates the entry’s timestamp in the database to tomorrow’s date at the same time.
  • If repeat_daily is false, it deletes the entry from the database.

The entire operation is transactional in nature: it will stop and return an error on the first failure.

§Arguments
  • feedschedule_entries - A mutable reference to a vector of FeedScheduleEntry structs to be processed.
§Returns

An empty Result (Ok(())) if all update and delete operations were successful.

§Errors

This function will return an error if an operation fails. This can be:

  • FeedScheduleUpdateFailure: If fetching tomorrow’s date fails.
  • FeedScheduleDropFailure: If a database UPDATE or DELETE command fails. This can be due to a lost connection or other database-side issues.
Source§

impl Debug for SqlInterfaceFeed

Source§

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

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

impl Pingable for SqlInterfaceFeed

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