39 lines
621 B
Go
39 lines
621 B
Go
package database
|
|
|
|
import (
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/database/model"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func Hosts() []model.Host {
|
|
var hosts []model.Host
|
|
|
|
GetDb().
|
|
Model(model.Host{}).
|
|
Preload("Infos", func(db *gorm.DB) *gorm.DB {
|
|
return db.Order("infos.id DESC")
|
|
}).
|
|
Order("name ASC").
|
|
Find(&hosts)
|
|
|
|
return hosts
|
|
}
|
|
|
|
func Host(id int) *model.Host {
|
|
var host model.Host
|
|
|
|
GetDb().
|
|
Model(model.Host{}).
|
|
Preload("Infos", func(db *gorm.DB) *gorm.DB {
|
|
return db.Order("infos.id DESC")
|
|
}).
|
|
Order("name ASC").
|
|
Where("id = ?", id).
|
|
First(&host)
|
|
|
|
if host.ID > 0 {
|
|
return &host
|
|
}
|
|
|
|
return nil
|
|
}
|