You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
"go_mqtt/mydb"
|
|
"time"
|
|
)
|
|
|
|
type TemperatureEsp struct {
|
|
Id int64 `gorm:"primaryKey;autoIncrement"`
|
|
CreateDate time.Time
|
|
DataDate string `gorm:"index:idx_dataDate;index:data_date_location_desc;size:20"`
|
|
DataHour string `gorm:"index:idx_dataHour;size:20"`
|
|
DataMinute string `gorm:"index:idx_dataMinute;size:20"`
|
|
Humidity string `gorm:"size:10"`
|
|
LocationDesc string `gorm:"index:idx_locationDesc;index:data_date_location_desc;size:80"`
|
|
Temperature string `gorm:"size:10"`
|
|
Topic string `gorm:"size:60"`
|
|
Source string `gorm:"size:10"`
|
|
}
|
|
|
|
func init() {
|
|
fmt.Println("TemperatureEsp init()")
|
|
mydb.DB.AutoMigrate(&TemperatureEsp{})
|
|
}
|
|
|
|
// TableName 会将 User 的表名重写为 `user`
|
|
func (TemperatureEsp) TableName() string {
|
|
return "temperature_esp"
|
|
}
|
|
|
|
func SaveTemperatureEsp(temperature *TemperatureEsp) {
|
|
result := mydb.DB.Create(&temperature)
|
|
if result.Error != nil {
|
|
fmt.Println("Failed to create TemperatureEsp:", result.Error)
|
|
} else {
|
|
fmt.Println("TemperatureEsp created successfully!")
|
|
}
|
|
}
|