32 lines
453 B
Go
32 lines
453 B
Go
|
package db
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
func (device *Device) Save() error {
|
||
|
if err := conn.Save(device).Error; err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
|
||
|
}
|
||
|
|
||
|
func (device *Device) Delete() error {
|
||
|
if err := conn.Delete(device).Error; err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
|
||
|
}
|
||
|
func CountDevices() int {
|
||
|
var count int64
|
||
|
err := conn.Model(&Device{}).Count(&count)
|
||
|
if err != nil {
|
||
|
count = 0
|
||
|
log.Println("Error counting devices: ")
|
||
|
}
|
||
|
|
||
|
return int(count)
|
||
|
}
|