记录信号强度数据
This commit is contained in:
27
internal/infra/repository/sensor_data_repository.go
Normal file
27
internal/infra/repository/sensor_data_repository.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// SensorDataRepository 定义了与传感器数据相关的数据库操作接口。
|
||||
type SensorDataRepository interface {
|
||||
Create(sensorData *models.SensorData) error
|
||||
}
|
||||
|
||||
// gormSensorDataRepository 是 SensorDataRepository 的 GORM 实现。
|
||||
type gormSensorDataRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewGormSensorDataRepository 创建一个新的 SensorDataRepository GORM 实现实例。
|
||||
// 它直接接收一个 *gorm.DB 实例作为依赖,完全遵循项目中的既定模式。
|
||||
func NewGormSensorDataRepository(db *gorm.DB) SensorDataRepository {
|
||||
return &gormSensorDataRepository{db: db}
|
||||
}
|
||||
|
||||
// Create 将一条新的传感器数据记录插入数据库。
|
||||
func (r *gormSensorDataRepository) Create(sensorData *models.SensorData) error {
|
||||
return r.db.Create(sensorData).Error
|
||||
}
|
||||
Reference in New Issue
Block a user