boilerplate code
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
create type sensor_type as enum (
|
||||
'temperature',
|
||||
'humidity',
|
||||
'carbon_dioxide',
|
||||
'pressure',
|
||||
'proximity',
|
||||
'light'
|
||||
);
|
||||
|
||||
create table sensors
|
||||
(
|
||||
sensor_id varchar(255) primary key,
|
||||
|
||||
sensor_type sensor_type not null,
|
||||
sampling_interval int not null default 3600,
|
||||
|
||||
threshold_above float not null default 100,
|
||||
threshold_below float not null default 0,
|
||||
|
||||
created_at timestamp not null default now(),
|
||||
updated_at timestamp not null default now()
|
||||
);
|
||||
|
||||
create index idx_sensors_sensor_id on sensors (sensor_id);
|
||||
|
||||
create table registry
|
||||
(
|
||||
sensor_id int not null references sensors (id),
|
||||
|
||||
value float not null,
|
||||
created_at timestamp not null default now()
|
||||
)
|
||||
with (
|
||||
timescaledb.hypertable,
|
||||
timescaledb.partition_column = 'created_at',
|
||||
timescaledb.segmentby = 'sensor_id'
|
||||
);
|
||||
+11
-2
@@ -3,17 +3,26 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"log/slog"
|
||||
"nats-app/internal/app"
|
||||
"nats-app/internal/domains/sensors"
|
||||
"nats-app/internal/iot"
|
||||
)
|
||||
|
||||
func main() {
|
||||
environment := flag.String("env", "dev", "dev or prod")
|
||||
flag.Parse()
|
||||
|
||||
_ = app.NewApp(*environment)
|
||||
pool := iot.NewPGXPool("postgres://developer:secret@localhost:5432/nats-db?sslmode=disable")
|
||||
|
||||
iotDevice := iot.Start(*environment, "nats://localhost:4222")
|
||||
|
||||
repo := sensors.NewDecoratorRepo(pool)
|
||||
sensorsService := sensors.NewService(repo)
|
||||
_ = sensors.NewHandlers(sensorsService, iotDevice).SetupEndpoints()
|
||||
|
||||
slog.Debug("hello world debug")
|
||||
slog.Info("Hello world info")
|
||||
slog.Warn("Hello world warn")
|
||||
slog.Error("hello world error")
|
||||
|
||||
select {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user