Documentation
¶
Index ¶
- func WriteDataRecordingToDatabase(config DatabaseConfig, dataRecording *DataRecording) (sql.Result, error)
- func WriteDeviceToDatabase(config DatabaseConfig, device *Device) (sql.Result, error)
- func WriteLocationToDatabase(config DatabaseConfig, location *Location) (sql.Result, error)
- type DB
- type DataRecording
- type DatabaseConfig
- type Device
- type Location
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteDataRecordingToDatabase ¶
func WriteDataRecordingToDatabase(config DatabaseConfig, dataRecording *DataRecording) (sql.Result, error)
WriteDataRecordingToDatabase inserts a new DataRecording into the "devices" table in the database specified by the provided config. It returns a sql.Result indicating the outcome of the insert operation and an error if any occurs during the process. The function establishes a database connection, constructs an SQL INSERT query using the data from the DataRecording struct, executes the query, and closes the database connection. A TODO comment notes the need to change to a prepared statement to avoid SQL injection risks.
func WriteDeviceToDatabase ¶
func WriteDeviceToDatabase(config DatabaseConfig, device *Device) (sql.Result, error)
WriteDeviceToDatabase inserts a new Device into the "devices" table in the database specified by the provided config. It returns a sql.Result indicating the outcome of the insert operation and an error if any occurs during the process. The function establishes a database connection, constructs an SQL INSERT query using the data from the Device struct, executes the query, and closes the database connection. A TODO comment highlights the need to switch to a prepared statement to mitigate SQL injection risks.
func WriteLocationToDatabase ¶
func WriteLocationToDatabase(config DatabaseConfig, location *Location) (sql.Result, error)
WriteLocationToDatabase inserts a new Location into the "locations" table in the database specified by the provided config. It returns a sql.Result indicating the outcome of the insert operation and an error if any occurs during the process. The function establishes a database connection, constructs an SQL INSERT query using the data from the Location struct, executes the query, and closes the database connection. A TODO comment highlights the need to switch to a prepared statement to prevent SQL injection risks.
Types ¶
type DataRecording ¶
type DataRecording struct { DeviceID string Timestamp time.Time Temperature float32 Humidity float32 AirQualityIndex float32 CO2Levels float32 LightIntensity float32 Occupancy bool SignalStrength int32 BatteryLevel int32 }
func GetDataRecordingsFromDatabase ¶
func GetDataRecordingsFromDatabase(config DatabaseConfig) ([]DataRecording, error)
GetDataRecordingsFromDatabase retrieves all data recordings from the "data_recordings" table in the database specified by the provided config. It returns a slice of DataRecording and an error if any occurs during the process. The function establishes a database connection, executes a query to select all records, scans each row into a DataRecording struct, and appends it to the result slice. If an error occurs at any point, the database connection is closed and the error is returned.
type DatabaseConfig ¶
type Device ¶
func GetDevicesFromDatabase ¶
func GetDevicesFromDatabase(config DatabaseConfig) ([]Device, error)
GetDevicesFromDatabase retrieves all devices from the "devices" table in the database specified by the provided config. It returns a slice of Device structs and an error if any occurs during the process. The function establishes a database connection, executes a query to select all records from the "devices" table, scans each row into a Device struct, and appends it to the result slice. If an error occurs at any point, the database connection is closed and the error is returned.
type Location ¶
func GetLocationsFromDatabase ¶
func GetLocationsFromDatabase(config DatabaseConfig) ([]Location, error)
GetLocationsFromDatabase retrieves all locations from the "locations" table in the database specified by the provided config. It returns a slice of Location structs and an error if any occurs during the process. The function establishes a database connection, executes a query to select all records from the "locations" table, scans each row into a Location struct, and appends it to the result slice. If an error occurs at any point, the database connection is closed and the error is returned.