package models
|
|
type CameraSensor struct {
|
CameraId string `json:"camera_id"`
|
SensorId string `json:"sensor_id"`
|
}
|
|
func (CameraSensor) TableName() string {
|
return "camera_sensor"
|
}
|
|
func (cs *CameraSensor) Exist(cameraId string, sensorId string) bool {
|
result := db.Table(cs.TableName()).Where("camera_id=? and sensor_id=?", cameraId, sensorId).First(&cs)
|
if result.Error != nil || result.RowsAffected ==0 {
|
return false
|
}
|
return true
|
}
|
|
func (cs *CameraSensor) Add() bool {
|
result := db.Table(cs.TableName()).Create(&cs)
|
if result.Error == nil && result.RowsAffected > 0 {
|
return true
|
}
|
return false
|
}
|
|
func (cs *CameraSensor) Delete(cameraId string, sensorId string) bool {
|
result := db.Exec("delete from camera_sensor where camera_id='"+cameraId+"' and sensor_id='"+sensorId+"'")
|
if result.Error == nil {
|
return true
|
}
|
|
return false
|
}
|
|
func (cs *CameraSensor) DeleteByCamId(cameraId string) bool {
|
result := db.Exec("delete from camera_sensor where camera_id='"+cameraId+"'")
|
if result.Error == nil {
|
return true
|
}
|
|
return false
|
}
|