44 lines
1.8 KiB
Go
44 lines
1.8 KiB
Go
// Package orm define database data struct
|
|
package orm
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/gofrs/uuid"
|
|
)
|
|
|
|
// Measurement structure define abstracted info set of electrical measurement
|
|
type Measurement struct {
|
|
ID int64 `gorm:"column:ID;primaryKey;autoIncrement"`
|
|
Tag string `gorm:"column:TAG;size:64;not null;default:''"`
|
|
Name string `gorm:"column:NAME;size:64;not null;default:''"`
|
|
Type int16 `gorm:"column:TYPE;not null;default:-1"`
|
|
Size int `gorm:"column:SIZE;not null;default:-1"`
|
|
DataSource map[string]interface{} `gorm:"column:DATA_SOURCE;type:jsonb;not null;default:'{}'"`
|
|
BayUUID uuid.UUID `gorm:"column:BAY_UUID;type:uuid;not null"`
|
|
ComponentUUID uuid.UUID `gorm:"column:COMPONENT_UUID;type:uuid;not null"`
|
|
Op int `gorm:"column:OP;not null;default:-1"`
|
|
Ts time.Time `gorm:"column:TS;type:timestamptz;not null;default:CURRENT_TIMESTAMP"`
|
|
}
|
|
|
|
// TableName func respresent return table name of Measurement
|
|
func (Measurement) TableName() string {
|
|
return "MEASUREMENT"
|
|
}
|
|
|
|
// CREATE TABLE PUBLIC.MEASUREMENT (
|
|
// ID BIGSERIAL PRIMARY KEY,
|
|
// TAG VARCHAR(64) NOT NULL DEFAULT '',
|
|
// NAME VARCHAR(64) NOT NULL DEFAULT '',
|
|
// TYPE SMALLINT NOT NULL DEFAULT -1,
|
|
// SIZE INTEGER NOT NULL DEFAULT -1,
|
|
// DATA_SOURCE JSONB NOT NULL DEFAULT '{}', -- {"type":1,"main_pos":"","sub_pos":""}
|
|
// BAY_UUID UUID NOT NULL,
|
|
// COMPONENT_UUID UUID NOT NULL,
|
|
// OP INTEGER NOT NULL DEFAULT -1,
|
|
// TS TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
// FOREIGN KEY (BAY_UUID) REFERENCES PUBLIC.BAY (BAY_UUID),
|
|
// FOREIGN KEY (COMPONENT_UUID) REFERENCES PUBLIC.COMPONENT (GLOBAL_UUID)
|
|
// );
|