fix: gnu-cc, missing humidity table, restrict repository select
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
||||
// Database is a general interface for a database backend like postgres, oracle
|
||||
// or sqlite
|
||||
type Database interface {
|
||||
Close() error
|
||||
DeleteDevices(ctx context.Context, deviceIDs ...string) error
|
||||
DeleteSensors(ctx context.Context, sensorIDs ...string) error
|
||||
InsertDevices(ctx context.Context, devices ...*types.Device) error
|
||||
@ -120,5 +121,4 @@ func New(dsnURL *url.URL, flogger logger.Logger) (Database, error) {
|
||||
}
|
||||
|
||||
return database, nil
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,12 @@ type Postgres struct {
|
||||
queries map[string]string
|
||||
}
|
||||
|
||||
// Close closes the database and prevents new queries from starting. Close then
|
||||
// waits for all queries that have started processing on the server to finish.
|
||||
func (postgres *Postgres) Close() error {
|
||||
return postgres.dbo.Close()
|
||||
}
|
||||
|
||||
// DeleteDevices from the database
|
||||
func (postgres *Postgres) DeleteDevices(ctx context.Context, deviceIDs ...string) error {
|
||||
queryFile := "deleteDevice.sql"
|
||||
@ -228,7 +234,7 @@ func (postgres *Postgres) Scheme(ctx context.Context) error {
|
||||
for _, query := range []string{
|
||||
postgres.queries["createTableDevices.sql"],
|
||||
postgres.queries["createTableSensors.sql"],
|
||||
postgres.queries["createTableHumidites.sql"],
|
||||
postgres.queries["createTableHumidities.sql"],
|
||||
postgres.queries["createTablePressures.sql"],
|
||||
postgres.queries["createTableTemperatures.sql"],
|
||||
} {
|
||||
|
@ -16,6 +16,12 @@ type SQLite struct {
|
||||
queries map[string]string
|
||||
}
|
||||
|
||||
// Close closes the database and prevents new queries from starting. Close then
|
||||
// waits for all queries that have started processing on the server to finish.
|
||||
func (sqlite *SQLite) Close() error {
|
||||
return sqlite.dbo.Close()
|
||||
}
|
||||
|
||||
// DeleteDevices from the database
|
||||
func (sqlite *SQLite) DeleteDevices(ctx context.Context, deviceIDs ...string) error {
|
||||
queryFile := "deleteDevice.sql"
|
||||
@ -227,7 +233,7 @@ func (sqlite *SQLite) Scheme(ctx context.Context) error {
|
||||
for _, query := range []string{
|
||||
sqlite.queries["createTableDevices.sql"],
|
||||
sqlite.queries["createTableSensors.sql"],
|
||||
sqlite.queries["createTableHumidites.sql"],
|
||||
sqlite.queries["createTableHumidities.sql"],
|
||||
sqlite.queries["createTablePressures.sql"],
|
||||
sqlite.queries["createTableTemperatures.sql"],
|
||||
} {
|
||||
|
@ -31,6 +31,13 @@ func (repo *Repository) AddSensors(sensors ...*types.Sensor) error {
|
||||
return repo.database.InsertSensors(context.Background(), sensors...)
|
||||
}
|
||||
|
||||
// Close closes the repository and prevents new queries from starting. Close
|
||||
// then waits for all queries that have started processing on the server to
|
||||
// finish.
|
||||
func (repo *Repository) Close() error {
|
||||
return repo.database.Close()
|
||||
}
|
||||
|
||||
// DisableSensorsByNames disable all sensors which match bei their name
|
||||
func (repo *Repository) DisableSensorsByNames(sensorNames ...string) error {
|
||||
sensors, err := repo.GetSensors()
|
||||
|
@ -278,7 +278,7 @@ func testBackend(t *testing.T, repo *repository.Repository) {
|
||||
{
|
||||
ID: "2e5a297a-3da0-46ae-89d2-0fcab0f1d5f7",
|
||||
Value: 32,
|
||||
ValueType: "temperature",
|
||||
ValueType: "humidity",
|
||||
Date: *timeNow(require),
|
||||
SensorID: "8c74397f-8e60-4c9d-960d-3197747cef9a",
|
||||
CreationDate: *timeNow(require),
|
||||
@ -287,7 +287,7 @@ func testBackend(t *testing.T, repo *repository.Repository) {
|
||||
{
|
||||
ID: "d69f1b62-0c6c-4058-b42c-4a2821bd220c",
|
||||
Value: 38,
|
||||
ValueType: "temperature",
|
||||
ValueType: "pressure",
|
||||
Date: *timeNow(require),
|
||||
SensorID: "8c74397f-8e60-4c9d-960d-3197747cef9a",
|
||||
CreationDate: *timeNow(require),
|
||||
|
Reference in New Issue
Block a user