-
Notifications
You must be signed in to change notification settings - Fork 41
/
hook.go
78 lines (65 loc) · 1.52 KB
/
hook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package model
import (
"encoding/json"
migapi "github.com/konveyor/mig-controller/pkg/apis/migration/v1alpha1"
)
// Hook model.
type Hook struct {
CR
}
// Update the model `with` a Hook.
func (m *Hook) With(object *migapi.MigHook) {
m.UID = string(object.UID)
m.Version = object.ResourceVersion
m.Namespace = object.Namespace
m.Name = object.Name
m.labels = object.Labels
m.EncodeObject(object)
}
// Encode the object.
func (m *Hook) EncodeObject(dim *migapi.MigHook) {
object, _ := json.Marshal(dim)
m.Object = string(object)
}
// Decode the object.
func (m *Hook) DecodeObject() *migapi.MigHook {
hook := &migapi.MigHook{}
json.Unmarshal([]byte(m.Object), hook)
return hook
}
// Count in the DB.
func (m Hook) Count(db DB, options ListOptions) (int64, error) {
return Table{db}.Count(&m, options)
}
// Fetch the model from the DB.
func (m Hook) List(db DB, options ListOptions) ([]*Hook, error) {
list := []*Hook{}
listed, err := Table{db}.List(&m, options)
if err != nil {
Log.Trace(err)
return nil, err
}
for _, intPtr := range listed {
list = append(list, intPtr.(*Hook))
}
return list, err
}
// Fetch the model from the DB.
func (m *Hook) Get(db DB) error {
return Table{db}.Get(m)
}
// Insert the model into the DB.
func (m *Hook) Insert(db DB) error {
m.SetPk()
return Table{db}.Insert(m)
}
// Update the model in the DB.
func (m *Hook) Update(db DB) error {
m.SetPk()
return Table{db}.Update(m)
}
// Delete the model in the DB.
func (m *Hook) Delete(db DB) error {
m.SetPk()
return Table{db}.Delete(m)
}