add read sensor query

This commit is contained in:
Pedro Pérez 2025-10-10 00:16:12 +02:00
parent 23ec2d5789
commit f6d94bff1a

View File

@ -50,10 +50,21 @@ func (p *pgxRepo) UpdateSensor(s Sensor) error {
return err
}
const readSensorBySensorID = ``
const readSensorBySensorID = `select sensor_id, sensor_type, sampling_interval, threshold_above, threshold_below from sensors where sensor_id = $1`
func (p *pgxRepo) ReadSensor(sensorID string) (Sensor, error) {
panic("unimplemented")
var s Sensor
err := p.QueryRow(context.Background(), readSensorBySensorID, sensorID).Scan(
&s.SensorID,
&s.SensorType,
&s.SamplingInterval,
&s.ThresholdAbove,
&s.ThresholdBelow,
)
if err != nil {
return Sensor{}, ErrSensorNotFound
}
return s, nil
}
const readSensorValuesBySensorID = ``