Module sql_interface_feed

Source
Expand description

Contains functions for execution of all queries relevant for feed (food) Manages all database interactions for the automated feeding system.

This module provides a dedicated interface, SqlInterfaceFeed, for handling all SQL operations related to the feeding schedule (feedschedule), feed patterns (feedpatterns), and feed event logging (feedlog).

§Key Components

  • SqlInterfaceFeed Struct: The primary struct that holds a database connection and provides methods for all feed-related database operations.

  • new() Constructor: A critical entry point that not only creates an SqlInterfaceFeed instance but also performs essential “fail-fast” validation. At initialization, it checks the database for:

    • The presence of NULL values in the feedpatterns and feedschedule tables.
    • Whether the number of rows in the feedpatterns, feedschedule, and feedlog tables exceeds the limits defined in the application configuration. This ensures the system doesn’t start in an invalid or inconsistent state.
  • Data-Fetching Methods: Functions like get_feedpattern_header_from_database and get_feed_phase_from_database provide a structured way to retrieve complex feed pattern data from the database.

§Design and Purpose

The main goal of this module is to provide a robust and encapsulated interface for the feeding subsystem’s data.

  • Encapsulation: All SQL queries and logic specific to feeding are contained within this module, separating concerns and making the overall database architecture cleaner.

  • Data Integrity: The constructor’s validation logic enforces data integrity rules at startup, preventing runtime errors caused by misconfigured or overgrown database tables

Structs§

SqlFeedPhase
Holds the data of one feed pattern phase as retrieved from the database. The numeric data is post-processed to boolean in a further step.
SqlFeedScheduleEntry
Holds the data of a feed schedule entry as retrieved from the database. It is post-processed in a further step.
SqlFeedpatternHeader
Holds the header information of a feed pattern.
SqlInterfaceFeed
Contains the configuration and the implementation of the SQL interface for Feed.