fix: implement repository pkg
This commit is contained in:
6
pkg/repository/db/sqlite3/createTableDevices.sql
Normal file
6
pkg/repository/db/sqlite3/createTableDevices.sql
Normal file
@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS devices (
|
||||
device_id CHAR(37) PRIMARY KEY,
|
||||
device_name VARCHAR(64) NOT NULL,
|
||||
device_location VARCHAR(64),
|
||||
creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
);
|
10
pkg/repository/db/sqlite3/createTableHumidities.sql
Normal file
10
pkg/repository/db/sqlite3/createTableHumidities.sql
Normal file
@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS humidities (
|
||||
humidity_id CHAR(37) PRIMARY KEY,
|
||||
humidity_value NUMERIC(10,3) NOT NULL,
|
||||
humidity_from_date TIMESTAMP NOT NULL,
|
||||
humidity_till_date TIMESTAMP,
|
||||
sensor_id CHAR(37) NOT NULL,
|
||||
creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
update_date TIMESTAMP,
|
||||
FOREIGN KEY(sensor_id) REFERENCES sensors(sensor_id)
|
||||
);
|
10
pkg/repository/db/sqlite3/createTablePressures.sql
Normal file
10
pkg/repository/db/sqlite3/createTablePressures.sql
Normal file
@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS pressures (
|
||||
pressure_id CHAR(37) PRIMARY KEY,
|
||||
pressure_value NUMERIC(10,3) NOT NULL,
|
||||
pressure_from_date TIMESTAMP NOT NULL,
|
||||
pressure_till_date TIMESTAMP,
|
||||
sensor_id CHAR(37) NOT NULL,
|
||||
creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
update_date TIMESTAMP,
|
||||
FOREIGN KEY(sensor_id) REFERENCES sensors(sensor_id)
|
||||
);
|
14
pkg/repository/db/sqlite3/createTableSensors.sql
Normal file
14
pkg/repository/db/sqlite3/createTableSensors.sql
Normal file
@ -0,0 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS sensors (
|
||||
sensor_id CHAR(37) PRIMARY KEY,
|
||||
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,
|
||||
device_id CHAR(37) NOT NULL,
|
||||
creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(device_id) REFERENCES devices(device_id)
|
||||
);
|
10
pkg/repository/db/sqlite3/createTableTemperatures.sql
Normal file
10
pkg/repository/db/sqlite3/createTableTemperatures.sql
Normal file
@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS temperatures (
|
||||
temperature_id CHAR(37) PRIMARY KEY,
|
||||
temperature_value NUMERIC(10,3) NOT NULL,
|
||||
temperature_from_date TIMESTAMP NOT NULL,
|
||||
temperature_till_date TIMESTAMP,
|
||||
sensor_id CHAR(37) NOT NULL,
|
||||
creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
update_date TIMESTAMP,
|
||||
FOREIGN KEY(sensor_id) REFERENCES sensors(sensor_id)
|
||||
);
|
2
pkg/repository/db/sqlite3/deleteDevice.sql
Normal file
2
pkg/repository/db/sqlite3/deleteDevice.sql
Normal file
@ -0,0 +1,2 @@
|
||||
DELETE FROM sensors
|
||||
WHERE device_id = $1;
|
2
pkg/repository/db/sqlite3/deleteSensor.sql
Normal file
2
pkg/repository/db/sqlite3/deleteSensor.sql
Normal file
@ -0,0 +1,2 @@
|
||||
DELETE FROM sensors
|
||||
WHERE sensor_id = $1;
|
7
pkg/repository/db/sqlite3/insertDevice.sql
Normal file
7
pkg/repository/db/sqlite3/insertDevice.sql
Normal file
@ -0,0 +1,7 @@
|
||||
INSERT INTO devices (
|
||||
device_id,
|
||||
device_name,
|
||||
device_location,
|
||||
creation_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4);
|
10
pkg/repository/db/sqlite3/insertHumidity.sql
Normal file
10
pkg/repository/db/sqlite3/insertHumidity.sql
Normal file
@ -0,0 +1,10 @@
|
||||
INSERT INTO humidities (
|
||||
humidity_id,
|
||||
humidity_value,
|
||||
humidity_from_date,
|
||||
humidity_till_date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7);
|
10
pkg/repository/db/sqlite3/insertPressure.sql
Normal file
10
pkg/repository/db/sqlite3/insertPressure.sql
Normal file
@ -0,0 +1,10 @@
|
||||
INSERT INTO pressures (
|
||||
pressure_id,
|
||||
pressure_value,
|
||||
pressure_from_date,
|
||||
pressure_till_date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7);
|
14
pkg/repository/db/sqlite3/insertSensor.sql
Normal file
14
pkg/repository/db/sqlite3/insertSensor.sql
Normal file
@ -0,0 +1,14 @@
|
||||
INSERT INTO sensors (
|
||||
sensor_id,
|
||||
sensor_name,
|
||||
sensor_location,
|
||||
wire_id,
|
||||
i2c_bus,
|
||||
i2c_address,
|
||||
gpio_number,
|
||||
sensor_model,
|
||||
sensor_enabled,
|
||||
device_id,
|
||||
creation_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);
|
10
pkg/repository/db/sqlite3/insertTemperature.sql
Normal file
10
pkg/repository/db/sqlite3/insertTemperature.sql
Normal file
@ -0,0 +1,10 @@
|
||||
INSERT INTO temperatures (
|
||||
temperature_id,
|
||||
temperature_value,
|
||||
temperature_from_date,
|
||||
temperature_till_date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7);
|
8
pkg/repository/db/sqlite3/selectDevice.sql
Normal file
8
pkg/repository/db/sqlite3/selectDevice.sql
Normal file
@ -0,0 +1,8 @@
|
||||
SELECT
|
||||
device_id,
|
||||
device_name,
|
||||
device_location,
|
||||
creation_date
|
||||
FROM
|
||||
devices
|
||||
WHERE device_id = $1;
|
7
pkg/repository/db/sqlite3/selectDevices.sql
Normal file
7
pkg/repository/db/sqlite3/selectDevices.sql
Normal file
@ -0,0 +1,7 @@
|
||||
SELECT
|
||||
device_id,
|
||||
device_name,
|
||||
device_location,
|
||||
creation_date
|
||||
FROM
|
||||
devices;
|
10
pkg/repository/db/sqlite3/selectHumidities.sql
Normal file
10
pkg/repository/db/sqlite3/selectHumidities.sql
Normal file
@ -0,0 +1,10 @@
|
||||
SELECT
|
||||
humidity_id,
|
||||
humidity_value,
|
||||
humidity_from_date,
|
||||
humidity_till_date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
humidities
|
12
pkg/repository/db/sqlite3/selectHumidity.sql
Normal file
12
pkg/repository/db/sqlite3/selectHumidity.sql
Normal file
@ -0,0 +1,12 @@
|
||||
SELECT
|
||||
humidity_id,
|
||||
humidity_value,
|
||||
humidity_from_date,
|
||||
humidity_till_date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
humidities
|
||||
WHERE
|
||||
humidity_id = $1
|
12
pkg/repository/db/sqlite3/selectPressure.sql
Normal file
12
pkg/repository/db/sqlite3/selectPressure.sql
Normal file
@ -0,0 +1,12 @@
|
||||
SELECT
|
||||
pressure_id,
|
||||
pressure_value,
|
||||
pressure_from_date,
|
||||
pressure_till_date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
pressures
|
||||
WHERE
|
||||
pressure_id = $1
|
10
pkg/repository/db/sqlite3/selectPressures.sql
Normal file
10
pkg/repository/db/sqlite3/selectPressures.sql
Normal file
@ -0,0 +1,10 @@
|
||||
SELECT
|
||||
pressure_id,
|
||||
pressure_value,
|
||||
pressure_from_date,
|
||||
pressure_till_date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
pressures
|
16
pkg/repository/db/sqlite3/selectSensor.sql
Normal file
16
pkg/repository/db/sqlite3/selectSensor.sql
Normal file
@ -0,0 +1,16 @@
|
||||
SELECT
|
||||
sensor_id,
|
||||
sensor_name,
|
||||
sensor_location,
|
||||
wire_id,
|
||||
i2c_bus,
|
||||
i2c_address,
|
||||
gpio_number,
|
||||
sensor_model,
|
||||
sensor_enabled,
|
||||
device_id,
|
||||
creation_date
|
||||
FROM
|
||||
sensors
|
||||
WHERE
|
||||
sensor_id = $1;
|
14
pkg/repository/db/sqlite3/selectSensors.sql
Normal file
14
pkg/repository/db/sqlite3/selectSensors.sql
Normal file
@ -0,0 +1,14 @@
|
||||
SELECT
|
||||
sensor_id,
|
||||
sensor_name,
|
||||
sensor_location,
|
||||
wire_id,
|
||||
i2c_bus,
|
||||
i2c_address,
|
||||
gpio_number,
|
||||
sensor_model,
|
||||
sensor_enabled,
|
||||
device_id,
|
||||
creation_date
|
||||
FROM
|
||||
sensors;
|
12
pkg/repository/db/sqlite3/selectTemperature.sql
Normal file
12
pkg/repository/db/sqlite3/selectTemperature.sql
Normal file
@ -0,0 +1,12 @@
|
||||
SELECT
|
||||
temperature_id,
|
||||
temperature_value,
|
||||
temperature_from_date,
|
||||
temperature_till_date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
temperatures
|
||||
WHERE
|
||||
temperature_id = $1
|
10
pkg/repository/db/sqlite3/selectTemperatures.sql
Normal file
10
pkg/repository/db/sqlite3/selectTemperatures.sql
Normal file
@ -0,0 +1,10 @@
|
||||
SELECT
|
||||
temperature_id,
|
||||
temperature_value,
|
||||
temperature_from_date,
|
||||
temperature_till_date,
|
||||
sensor_id,
|
||||
creation_date,
|
||||
update_date
|
||||
FROM
|
||||
temperatures
|
7
pkg/repository/db/sqlite3/updateDevice.sql
Normal file
7
pkg/repository/db/sqlite3/updateDevice.sql
Normal file
@ -0,0 +1,7 @@
|
||||
UPDATE device
|
||||
SET
|
||||
device_name = $1,
|
||||
device_location = $2,
|
||||
creation_date = $3
|
||||
WHERE
|
||||
device_id = $4,
|
14
pkg/repository/db/sqlite3/updateSensor.sql
Normal file
14
pkg/repository/db/sqlite3/updateSensor.sql
Normal file
@ -0,0 +1,14 @@
|
||||
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,
|
||||
device_id = $9,
|
||||
creation_date = $10
|
||||
WHERE
|
||||
sensor_id = $11;
|
Reference in New Issue
Block a user