goipam/db/devices.go

32 lines
453 B
Go
Raw Permalink Normal View History

2024-02-22 20:52:37 +01:00
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)
}