statping/types/hits/database.go

40 lines
620 B
Go
Raw Normal View History

2020-03-04 10:29:00 +00:00
package hits
2020-03-04 14:20:47 +00:00
import (
"github.com/hunterlong/statping/database"
"github.com/hunterlong/statping/utils"
)
var log = utils.Log
2020-03-04 10:29:00 +00:00
func DB() database.Database {
return database.DB().Model(&Hit{})
}
func Find(id int64) (*Hit, error) {
2020-03-06 03:03:18 +00:00
var group Hit
2020-03-04 10:29:00 +00:00
db := DB().Where("id = ?", id).Find(&group)
2020-03-06 03:03:18 +00:00
return &group, db.Error()
2020-03-04 10:29:00 +00:00
}
func All() []*Hit {
var hits []*Hit
DB().Find(&hits)
return hits
}
func (h *Hit) Create() error {
2020-03-06 03:03:18 +00:00
db := DB().Create(h)
2020-03-04 10:29:00 +00:00
return db.Error()
}
func (h *Hit) Update() error {
2020-03-06 03:03:18 +00:00
db := DB().Update(h)
2020-03-04 10:29:00 +00:00
return db.Error()
}
func (h *Hit) Delete() error {
2020-03-06 03:03:18 +00:00
db := DB().Delete(h)
2020-03-04 10:29:00 +00:00
return db.Error()
}