refac: use embed instead of go-bindata, secure closing of transactions

This commit is contained in:
2021-03-21 18:47:14 +01:00
parent 59db7cfc85
commit 7a88aaac0c
98 changed files with 3147 additions and 2525 deletions

View File

@ -0,0 +1 @@
DROP TABLE devices;

View File

@ -0,0 +1,8 @@
CREATE TABLE devices (
device_id CHAR(36) NOT NULL,
device_name VARCHAR(64) NOT NULL,
device_location VARCHAR(64),
creation_date TIMESTAMP DEFAULT (datetime('now', 'localtime')) NOT NULL,
update_date TIMESTAMP,
CONSTRAINT pk_devices PRIMARY KEY (device_id)
);

View File

@ -0,0 +1 @@
DROP TABLE sensors;

View File

@ -0,0 +1,17 @@
CREATE TABLE sensors (
sensor_id CHAR(36) NOT NULL,
sensor_name VARCHAR(64) NOT NULL,
sensor_location VARCHAR(64),
wire_id VARCHAR(64),
i2c_bus VARCHAR(255),
i2c_address VARCHAR(12),
gpio_number VARCHAR(6),
sensor_model VARCHAR(16) NOT NULL,
sensor_enabled INTEGER(1) DEFAULT 1 NOT NULL,
tick_duration VARCHAR(6) NOT NULL,
device_id CHAR(36) NOT NULL,
creation_date TIMESTAMP DEFAULT (datetime('now', 'localtime')) NOT NULL,
update_date TIMESTAMP,
CONSTRAINT pk_sensors PRIMARY KEY(sensor_id),
CONSTRAINT fk_sensors_device_id FOREIGN KEY(device_id) REFERENCES devices(device_id) ON DELETE CASCADE ON UPDATE CASCADE
);

View File

@ -0,0 +1 @@
DROP TABLE humidities;

View File

@ -0,0 +1,10 @@
CREATE TABLE humidities (
id CHAR(36) NOT NULL,
value NUMERIC(10,3) NOT NULL,
date TIMESTAMP NOT NULL,
sensor_id CHAR(36) NOT NULL,
creation_date TIMESTAMP DEFAULT (datetime('now', 'localtime')) NOT NULL,
update_date TIMESTAMP,
CONSTRAINT pk_humidities PRIMARY KEY(id),
CONSTRAINT fk_humidities_sensor_id FOREIGN KEY(sensor_id) REFERENCES sensors(sensor_id) ON DELETE CASCADE ON UPDATE CASCADE
);

View File

@ -0,0 +1 @@
DROP TABLE humidities;

View File

@ -0,0 +1,10 @@
CREATE TABLE pressures (
id CHAR(36) NOT NULL,
value NUMERIC(10,3) NOT NULL,
date TIMESTAMP NOT NULL,
sensor_id CHAR(36) NOT NULL,
creation_date TIMESTAMP DEFAULT (datetime('now', 'localtime')) NOT NULL,
update_date TIMESTAMP,
CONSTRAINT pk_pressures PRIMARY KEY(id),
CONSTRAINT fk_pressures_sensor_id FOREIGN KEY(sensor_id) REFERENCES sensors(sensor_id) ON DELETE CASCADE ON UPDATE CASCADE
);

View File

@ -0,0 +1 @@
DROP TABLE temperatures;

View File

@ -0,0 +1,10 @@
CREATE TABLE temperatures (
id CHAR(36) NOT NULL,
value NUMERIC(10,3) NOT NULL,
date TIMESTAMP NOT NULL,
sensor_id CHAR(36) NOT NULL,
creation_date TIMESTAMP DEFAULT (datetime('now', 'localtime')) NOT NULL,
update_date TIMESTAMP,
CONSTRAINT pk_temperatures PRIMARY KEY(id),
CONSTRAINT fk_temperatures_id FOREIGN KEY(sensor_id) REFERENCES sensors(sensor_id) ON DELETE CASCADE ON UPDATE CASCADE
);

View File

@ -0,0 +1,2 @@
DELETE FROM devices
WHERE device_id = $1;

View File

@ -0,0 +1,2 @@
DELETE FROM devices
WHERE device_name = $1;

View File

@ -0,0 +1,2 @@
DELETE FROM sensors
WHERE sensor_id = $1;

View File

@ -0,0 +1,2 @@
DELETE FROM sensors
WHERE sensor_name = $1;

View File

@ -0,0 +1,8 @@
INSERT INTO devices (
device_id,
device_name,
device_location,
creation_date,
update_date
)
VALUES ($1, $2, $3, $4, $5);

View File

@ -0,0 +1,9 @@
INSERT INTO humidities (
id,
value,
date,
sensor_id,
creation_date,
update_date
)
VALUES ($1, $2, $3, $4, $5, $6);

View 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');

View 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');

View 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');

View 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');

View 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');

View File

@ -0,0 +1,9 @@
INSERT INTO pressures (
id,
value,
date,
sensor_id,
creation_date,
update_date
)
VALUES ($1, $2, $3, $4, $5, $6);

View File

@ -0,0 +1,16 @@
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);

View File

@ -0,0 +1,9 @@
INSERT INTO temperatures (
id,
value,
date,
sensor_id,
creation_date,
update_date
)
VALUES ($1, $2, $3, $4, $5, $6);

View File

@ -0,0 +1,9 @@
SELECT
device_id,
device_name,
device_location,
creation_date,
update_date
FROM
devices
WHERE device_id = $1;

View File

@ -0,0 +1,9 @@
SELECT
device_id,
device_name,
device_location,
creation_date,
update_date
FROM
devices
WHERE device_name = $1;

View File

@ -0,0 +1,8 @@
SELECT
device_id,
device_name,
device_location,
creation_date,
update_date
FROM
devices;

View File

@ -0,0 +1,9 @@
SELECT
id,
value,
date,
sensor_id,
creation_date,
update_date
FROM
humidities

View File

@ -0,0 +1,11 @@
SELECT
id,
value,
date,
sensor_id,
creation_date,
update_date
FROM
humidities
WHERE
id = $1

View File

@ -0,0 +1,11 @@
SELECT
id,
value,
date,
sensor_id,
creation_date,
update_date
FROM
pressures
WHERE
id = $1

View File

@ -0,0 +1,9 @@
SELECT
id,
value,
date,
sensor_id,
creation_date,
update_date
FROM
pressures

View File

@ -0,0 +1,18 @@
SELECT
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
FROM
sensors
WHERE
sensor_id = $1;

View File

@ -0,0 +1,18 @@
SELECT
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
FROM
sensors
ORDER BY
sensor_id;

View File

@ -0,0 +1,18 @@
SELECT
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
FROM
sensors
WHERE
device_id = $1;

View File

@ -0,0 +1,18 @@
SELECT
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
FROM
sensors
WHERE
sensor_model = $1;

View File

@ -0,0 +1,18 @@
SELECT
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
FROM
sensors
WHERE
sensor_name = $1;

View File

@ -0,0 +1,11 @@
SELECT
id,
value,
date,
sensor_id,
creation_date,
update_date
FROM
temperatures
WHERE
id = $1

View File

@ -0,0 +1,9 @@
SELECT
id,
value,
date,
sensor_id,
creation_date,
update_date
FROM
temperatures

View File

@ -0,0 +1,8 @@
UPDATE devices
SET
device_name = $1,
device_location = $2,
creation_date = $3,
update_date = $4
WHERE
device_id = $5

View File

@ -0,0 +1,16 @@
UPDATE sensors
SET
sensor_name = $1,
sensor_location = $2,
wire_id = $3,
i2c_bus = $4,
i2c_address = $5,
gpio_number = $6,
sensor_model = $7,
sensor_enabled = $8,
tick_duration = $9,
device_id = $10,
creation_date = $11,
update_date = $12
WHERE
sensor_id = $13;

File diff suppressed because it is too large Load Diff