2020-03-04 10:29:00 +00:00
|
|
|
package hits
|
|
|
|
|
2020-03-04 14:20:47 +00:00
|
|
|
import (
|
2020-03-09 18:17:55 +00:00
|
|
|
"github.com/statping/statping/database"
|
2020-06-13 01:13:28 +00:00
|
|
|
"github.com/statping/statping/types/metrics"
|
2020-03-09 18:17:55 +00:00
|
|
|
"github.com/statping/statping/utils"
|
2020-03-04 14:20:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var log = utils.Log
|
2020-03-04 10:29:00 +00:00
|
|
|
|
2020-03-10 05:24:35 +00:00
|
|
|
var db database.Database
|
|
|
|
|
|
|
|
func SetDB(database database.Database) {
|
|
|
|
db = database.Model(&Hit{})
|
2020-03-04 10:29:00 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 11:02:14 +00:00
|
|
|
func (h *Hit) AfterFind() {
|
|
|
|
metrics.Query("hit", "find")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Hit) AfterUpdate() {
|
|
|
|
metrics.Query("hit", "update")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Hit) AfterDelete() {
|
|
|
|
metrics.Query("hit", "delete")
|
|
|
|
}
|
|
|
|
|
2020-06-13 01:13:28 +00:00
|
|
|
func (h *Hit) AfterCreate() {
|
2020-06-16 11:02:14 +00:00
|
|
|
metrics.Query("hit", "create")
|
2020-06-13 01:13:28 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 10:29:00 +00:00
|
|
|
func (h *Hit) Create() error {
|
2020-03-10 05:24:35 +00:00
|
|
|
q := db.Create(h)
|
|
|
|
return q.Error()
|
2020-03-04 10:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Hit) Update() error {
|
2020-03-10 05:24:35 +00:00
|
|
|
q := db.Update(h)
|
|
|
|
return q.Error()
|
2020-03-04 10:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Hit) Delete() error {
|
2020-03-10 05:24:35 +00:00
|
|
|
q := db.Delete(h)
|
|
|
|
return q.Error()
|
2020-03-04 10:29:00 +00:00
|
|
|
}
|