storage

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

- Uses TimescaleDB for storing measurements in hypertables. - TimescaleDB tables do not support primary keys. - Contains CRUD operations for sensor_measurement table.

- Contains CRUD operations for sensor table.

Index

Constants

This section is empty.

Variables

View Source
var (
	PostgresConnString = os.Getenv("POSTGRES_CONN_STRING")
)

Relational Database

Functions

func DeleteSensor

func DeleteSensor(serialNumber string) error

func GetSensorIDBySerialNumber

func GetSensorIDBySerialNumber(serialNumber string) (sensorID int, err error)

func WriteLog

func WriteLog(sensorLog SensorLogRecord) error

func WriteSensor

func WriteSensor(sr SensorRecord) error

func WriteTarget

func WriteTarget(tr TargetRecord) error

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func NewDBPool

func NewDBPool(connString string) (*DB, error)

func (*DB) Close

func (db *DB) Close()

func (*DB) WriteMeasurement

func (DB *DB) WriteMeasurement(ctx context.Context, measurement SensorMeasurementRecord) error

type SensorLogRecord

type SensorLogRecord struct {
	Timestamp    time.Time `json:"timestamp"`
	SerialNumber string    `json:"serialNumber"`
	Level        string    `json:"level"`
	Message      string    `json:"message"`
}

type SensorMeasurementRecord

type SensorMeasurementRecord struct {
	Timestamp   time.Time
	SensorID    int
	Measurement float64
}

timescaleDB hypertable -- Does not support primary keys

type SensorRecord

type SensorRecord struct {
	ID              int     `json:"id"`
	SerialNumber    string  `json:"serial_number"`
	SampleFrequency float64 `json:"sample_frequency"`
}

func GetSensor

func GetSensor() ([]SensorRecord, error)

func GetSensorBySerialNumber

func GetSensorBySerialNumber(serialNumber string) (sensor SensorRecord, err error)

type TargetRecord

type TargetRecord struct {
	ID   int
	Name string
}

TODO: add created_at and updated_at audit fields

func GetTarget

func GetTarget() ([]TargetRecord, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL