fix: add or update devices, sensors and measured values
Add additional functions to the repository to add or update devices, sensors or measured values. Furthermore the test has been adapt to the new functions.
This commit is contained in:
14
pkg/repository/db/sqlite3/insertOrUpdateDevice.sql
Normal file
14
pkg/repository/db/sqlite3/insertOrUpdateDevice.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
INSERT INTO devices (
|
||||
device_id,
|
||||
device_name,
|
||||
device_location,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
ON CONFLICT (device_id)
|
||||
DO
|
||||
UPDATE SET
|
||||
device_name = EXCLUDED.device_name,
|
||||
device_location = EXCLUDED.device_location,
|
||||
update_date = date('now');
|
16
pkg/repository/db/sqlite3/insertOrUpdateHumidity.sql
Normal file
16
pkg/repository/db/sqlite3/insertOrUpdateHumidity.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
INSERT INTO humidities (
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (id)
|
||||
DO
|
||||
UPDATE SET
|
||||
value = EXCLUDED.value,
|
||||
date = EXCLUDED.date,
|
||||
sensor_id = EXCLUDED.sensor_id,
|
||||
update_date = date('now');
|
16
pkg/repository/db/sqlite3/insertOrUpdatePressure.sql
Normal file
16
pkg/repository/db/sqlite3/insertOrUpdatePressure.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
INSERT INTO pressures (
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (id)
|
||||
DO
|
||||
UPDATE SET
|
||||
value = EXCLUDED.value,
|
||||
date = EXCLUDED.date,
|
||||
sensor_id = EXCLUDED.sensor_id,
|
||||
update_date = date('now');
|
31
pkg/repository/db/sqlite3/insertOrUpdateSensor.sql
Normal file
31
pkg/repository/db/sqlite3/insertOrUpdateSensor.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
INSERT INTO sensors (
|
||||
sensor_id,
|
||||
sensor_name,
|
||||
sensor_location,
|
||||
wire_id,
|
||||
i2c_bus,
|
||||
i2c_address,
|
||||
gpio_number,
|
||||
sensor_model,
|
||||
sensor_enabled,
|
||||
tick_duration,
|
||||
device_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
||||
ON CONFLICT (sensor_id)
|
||||
DO
|
||||
UPDATE SET
|
||||
sensor_name = EXCLUDED.sensor_name,
|
||||
sensor_location = EXCLUDED.sensor_location,
|
||||
wire_id = EXCLUDED.wire_id,
|
||||
i2c_bus = EXCLUDED.i2c_bus,
|
||||
i2c_address = EXCLUDED.i2c_address,
|
||||
gpio_number = EXCLUDED.gpio_number,
|
||||
sensor_model = EXCLUDED.sensor_model,
|
||||
sensor_enabled = EXCLUDED.sensor_enabled,
|
||||
tick_duration = EXCLUDED.tick_duration,
|
||||
device_id = EXCLUDED.device_id,
|
||||
creation_date = EXCLUDED.creation_date,
|
||||
update_date = date('now');
|
16
pkg/repository/db/sqlite3/insertOrUpdateTemperature.sql
Normal file
16
pkg/repository/db/sqlite3/insertOrUpdateTemperature.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
INSERT INTO temperatures (
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (id)
|
||||
DO
|
||||
UPDATE SET
|
||||
value = EXCLUDED.value,
|
||||
date = EXCLUDED.date,
|
||||
sensor_id = EXCLUDED.sensor_id,
|
||||
update_date = date('now');
|
@@ -8,4 +8,4 @@ SELECT
|
||||
FROM
|
||||
humidities
|
||||
WHERE
|
||||
humidity_id = $1
|
||||
id = $1
|
@@ -8,4 +8,4 @@ SELECT
|
||||
FROM
|
||||
pressures
|
||||
WHERE
|
||||
pressure_id = $1
|
||||
id = $1
|
@@ -8,4 +8,4 @@ SELECT
|
||||
FROM
|
||||
temperatures
|
||||
WHERE
|
||||
temperature_id = $1
|
||||
id = $1
|
Reference in New Issue
Block a user