refac: use embed instead of go-bindata, secure closing of transactions
This commit is contained in:
1
pkg/repository/sqlite3/ddl/1_table_devices.down.sql
Normal file
1
pkg/repository/sqlite3/ddl/1_table_devices.down.sql
Normal file
@ -0,0 +1 @@
|
||||
DROP TABLE devices;
|
8
pkg/repository/sqlite3/ddl/1_table_devices.up.sql
Normal file
8
pkg/repository/sqlite3/ddl/1_table_devices.up.sql
Normal 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)
|
||||
);
|
1
pkg/repository/sqlite3/ddl/2_table_sensors.down.sql
Normal file
1
pkg/repository/sqlite3/ddl/2_table_sensors.down.sql
Normal file
@ -0,0 +1 @@
|
||||
DROP TABLE sensors;
|
17
pkg/repository/sqlite3/ddl/2_table_sensors.up.sql
Normal file
17
pkg/repository/sqlite3/ddl/2_table_sensors.up.sql
Normal 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
|
||||
);
|
1
pkg/repository/sqlite3/ddl/3_table_humidities.down.sql
Normal file
1
pkg/repository/sqlite3/ddl/3_table_humidities.down.sql
Normal file
@ -0,0 +1 @@
|
||||
DROP TABLE humidities;
|
10
pkg/repository/sqlite3/ddl/3_table_humidities.up.sql
Normal file
10
pkg/repository/sqlite3/ddl/3_table_humidities.up.sql
Normal 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
|
||||
);
|
1
pkg/repository/sqlite3/ddl/4_table_pressures.down.sql
Normal file
1
pkg/repository/sqlite3/ddl/4_table_pressures.down.sql
Normal file
@ -0,0 +1 @@
|
||||
DROP TABLE humidities;
|
10
pkg/repository/sqlite3/ddl/4_table_pressures.up.sql
Normal file
10
pkg/repository/sqlite3/ddl/4_table_pressures.up.sql
Normal 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
|
||||
);
|
1
pkg/repository/sqlite3/ddl/5_table_temperatures.down.sql
Normal file
1
pkg/repository/sqlite3/ddl/5_table_temperatures.down.sql
Normal file
@ -0,0 +1 @@
|
||||
DROP TABLE temperatures;
|
10
pkg/repository/sqlite3/ddl/5_table_temperatures.up.sql
Normal file
10
pkg/repository/sqlite3/ddl/5_table_temperatures.up.sql
Normal 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
|
||||
);
|
2
pkg/repository/sqlite3/dml/deleteDeviceByID.sql
Normal file
2
pkg/repository/sqlite3/dml/deleteDeviceByID.sql
Normal file
@ -0,0 +1,2 @@
|
||||
DELETE FROM devices
|
||||
WHERE device_id = $1;
|
2
pkg/repository/sqlite3/dml/deleteDeviceByName.sql
Normal file
2
pkg/repository/sqlite3/dml/deleteDeviceByName.sql
Normal file
@ -0,0 +1,2 @@
|
||||
DELETE FROM devices
|
||||
WHERE device_name = $1;
|
2
pkg/repository/sqlite3/dml/deleteSensorByID.sql
Normal file
2
pkg/repository/sqlite3/dml/deleteSensorByID.sql
Normal file
@ -0,0 +1,2 @@
|
||||
DELETE FROM sensors
|
||||
WHERE sensor_id = $1;
|
2
pkg/repository/sqlite3/dml/deleteSensorByName.sql
Normal file
2
pkg/repository/sqlite3/dml/deleteSensorByName.sql
Normal file
@ -0,0 +1,2 @@
|
||||
DELETE FROM sensors
|
||||
WHERE sensor_name = $1;
|
8
pkg/repository/sqlite3/dml/insertDevice.sql
Normal file
8
pkg/repository/sqlite3/dml/insertDevice.sql
Normal file
@ -0,0 +1,8 @@
|
||||
INSERT INTO devices (
|
||||
device_id,
|
||||
device_name,
|
||||
device_location,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5);
|
9
pkg/repository/sqlite3/dml/insertHumidity.sql
Normal file
9
pkg/repository/sqlite3/dml/insertHumidity.sql
Normal file
@ -0,0 +1,9 @@
|
||||
INSERT INTO humidities (
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6);
|
14
pkg/repository/sqlite3/dml/insertOrUpdateDevice.sql
Normal file
14
pkg/repository/sqlite3/dml/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/sqlite3/dml/insertOrUpdateHumidity.sql
Normal file
16
pkg/repository/sqlite3/dml/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/sqlite3/dml/insertOrUpdatePressure.sql
Normal file
16
pkg/repository/sqlite3/dml/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/sqlite3/dml/insertOrUpdateSensor.sql
Normal file
31
pkg/repository/sqlite3/dml/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/sqlite3/dml/insertOrUpdateTemperature.sql
Normal file
16
pkg/repository/sqlite3/dml/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');
|
9
pkg/repository/sqlite3/dml/insertPressure.sql
Normal file
9
pkg/repository/sqlite3/dml/insertPressure.sql
Normal file
@ -0,0 +1,9 @@
|
||||
INSERT INTO pressures (
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6);
|
16
pkg/repository/sqlite3/dml/insertSensor.sql
Normal file
16
pkg/repository/sqlite3/dml/insertSensor.sql
Normal 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);
|
9
pkg/repository/sqlite3/dml/insertTemperature.sql
Normal file
9
pkg/repository/sqlite3/dml/insertTemperature.sql
Normal file
@ -0,0 +1,9 @@
|
||||
INSERT INTO temperatures (
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6);
|
9
pkg/repository/sqlite3/dml/selectDeviceByID.sql
Normal file
9
pkg/repository/sqlite3/dml/selectDeviceByID.sql
Normal file
@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
device_id,
|
||||
device_name,
|
||||
device_location,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
devices
|
||||
WHERE device_id = $1;
|
9
pkg/repository/sqlite3/dml/selectDeviceByName.sql
Normal file
9
pkg/repository/sqlite3/dml/selectDeviceByName.sql
Normal file
@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
device_id,
|
||||
device_name,
|
||||
device_location,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
devices
|
||||
WHERE device_name = $1;
|
8
pkg/repository/sqlite3/dml/selectDevices.sql
Normal file
8
pkg/repository/sqlite3/dml/selectDevices.sql
Normal file
@ -0,0 +1,8 @@
|
||||
SELECT
|
||||
device_id,
|
||||
device_name,
|
||||
device_location,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
devices;
|
9
pkg/repository/sqlite3/dml/selectHumidities.sql
Normal file
9
pkg/repository/sqlite3/dml/selectHumidities.sql
Normal file
@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
humidities
|
11
pkg/repository/sqlite3/dml/selectHumidityByID.sql
Normal file
11
pkg/repository/sqlite3/dml/selectHumidityByID.sql
Normal file
@ -0,0 +1,11 @@
|
||||
SELECT
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
humidities
|
||||
WHERE
|
||||
id = $1
|
11
pkg/repository/sqlite3/dml/selectPressureByID.sql
Normal file
11
pkg/repository/sqlite3/dml/selectPressureByID.sql
Normal file
@ -0,0 +1,11 @@
|
||||
SELECT
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
pressures
|
||||
WHERE
|
||||
id = $1
|
9
pkg/repository/sqlite3/dml/selectPressures.sql
Normal file
9
pkg/repository/sqlite3/dml/selectPressures.sql
Normal file
@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
pressures
|
18
pkg/repository/sqlite3/dml/selectSensorByID.sql
Normal file
18
pkg/repository/sqlite3/dml/selectSensorByID.sql
Normal 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;
|
18
pkg/repository/sqlite3/dml/selectSensors.sql
Normal file
18
pkg/repository/sqlite3/dml/selectSensors.sql
Normal 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;
|
18
pkg/repository/sqlite3/dml/selectSensorsByDeviceID.sql
Normal file
18
pkg/repository/sqlite3/dml/selectSensorsByDeviceID.sql
Normal 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;
|
18
pkg/repository/sqlite3/dml/selectSensorsByModel.sql
Normal file
18
pkg/repository/sqlite3/dml/selectSensorsByModel.sql
Normal 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;
|
18
pkg/repository/sqlite3/dml/selectSensorsByName.sql
Normal file
18
pkg/repository/sqlite3/dml/selectSensorsByName.sql
Normal 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;
|
11
pkg/repository/sqlite3/dml/selectTemperatureByID.sql
Normal file
11
pkg/repository/sqlite3/dml/selectTemperatureByID.sql
Normal file
@ -0,0 +1,11 @@
|
||||
SELECT
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
temperatures
|
||||
WHERE
|
||||
id = $1
|
9
pkg/repository/sqlite3/dml/selectTemperatures.sql
Normal file
9
pkg/repository/sqlite3/dml/selectTemperatures.sql
Normal file
@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
id,
|
||||
value,
|
||||
date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
temperatures
|
8
pkg/repository/sqlite3/dml/updateDevice.sql
Normal file
8
pkg/repository/sqlite3/dml/updateDevice.sql
Normal file
@ -0,0 +1,8 @@
|
||||
UPDATE devices
|
||||
SET
|
||||
device_name = $1,
|
||||
device_location = $2,
|
||||
creation_date = $3,
|
||||
update_date = $4
|
||||
WHERE
|
||||
device_id = $5
|
16
pkg/repository/sqlite3/dml/updateSensor.sql
Normal file
16
pkg/repository/sqlite3/dml/updateSensor.sql
Normal 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;
|
1256
pkg/repository/sqlite3/sqlite.go
Normal file
1256
pkg/repository/sqlite3/sqlite.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user