dbwrapper

package
v0.0.0-...-dc4467a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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 DB

type DB struct {
	// contains filtered or unexported fields
}

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 DatabaseConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	Name     string
	Schema   string
}

type Device

type Device struct {
	DeviceID        string
	RoomID          string
	FirmwareVersion string
	Address         string
}

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

type Location struct {
	RoomID    string
	Latitude  float32
	Longitude float32
	Altitude  float32
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL