-
Notifications
You must be signed in to change notification settings - Fork 1
/
sql.go
180 lines (148 loc) · 4.73 KB
/
sql.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package asset
import (
"database/sql/driver"
"github.com/substra/orchestrator/lib/errors"
"google.golang.org/protobuf/encoding/protojson"
)
// Value implements the driver.Valuer interface.
// Simply returns the JSON-encoded representation of the Permissions.
func (p *Permissions) Value() (driver.Value, error) {
return protojson.Marshal(p)
}
// Scan implements the sql.Scanner interface.
// Simply decodes JSON into the Permissions.
func (p *Permissions) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.NewError(errors.ErrByteArray, "cannot scan permissions")
}
return protojson.Unmarshal(b, p)
}
// Value implements the driver.Valuer interface.
// Simply returns the JSON-encoded representation of the Permission.
func (p *Permission) Value() (driver.Value, error) {
return protojson.Marshal(p)
}
// Scan implements the sql.Scanner interface.
// Simply decodes JSON into the Permission.
func (p *Permission) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.NewError(errors.ErrByteArray, "cannot scan permission")
}
return protojson.Unmarshal(b, p)
}
// Value implements the driver.Valuer interface.
// Simply returns the string representation of the ComputeTaskStatus.
func (ts *ComputeTaskStatus) Value() (driver.Value, error) {
return ts.String(), nil
}
// Scan implements the sql.Scanner interface.
// Simply decodes a string into the ComputeTaskStatus.
func (ts *ComputeTaskStatus) Scan(value interface{}) error {
s, ok := value.(string)
if !ok {
return errors.NewInternal("cannot scan task status: invalid string")
}
v, ok := ComputeTaskStatus_value[s]
if !ok {
return errors.NewInternal("cannot scan task status: unknown value")
}
*ts = ComputeTaskStatus(v)
return nil
}
// Value implements the driver.Valuer interface.
// Simply returns the string representation of the ErrorType.
func (e *ErrorType) Value() (driver.Value, error) {
return e.String(), nil
}
// Scan implements the sql.Scanner interface.
// Simply decodes a string into the ErrorType.
func (e *ErrorType) Scan(value interface{}) error {
s, ok := value.(string)
if !ok {
return errors.NewError(errors.ErrInternal, "cannot scan error type")
}
v, ok := ErrorType_value[s]
if !ok {
return errors.NewError(errors.ErrInternal, "cannot scan error type")
}
*e = ErrorType(v)
return nil
}
// Value implements the driver.Valuer interface.
// Simply returns the string representation of the AssetKind.
func (k *AssetKind) Value() (driver.Value, error) {
return k.String(), nil
}
// Scan implements the sql.Scanner interface.
// Simply decodes a string into the AssetKind.
func (k *AssetKind) Scan(value interface{}) error {
s, ok := value.(string)
if !ok {
return errors.NewError(errors.ErrInternal, "cannot scan asset kind")
}
v, ok := AssetKind_value[s]
if !ok {
return errors.NewError(errors.ErrInternal, "cannot scan asset kind")
}
*k = AssetKind(v)
return nil
}
// Value implements the driver.Valuer interface.
// Simply returns the string representation of the EventKind.
func (k *EventKind) Value() (driver.Value, error) {
return k.String(), nil
}
// Scan implements the sql.Scanner interface.
// Simply decodes a string into the EventKind.
func (k *EventKind) Scan(value interface{}) error {
s, ok := value.(string)
if !ok {
return errors.NewError(errors.ErrInternal, "cannot scan event kind")
}
v, ok := EventKind_value[s]
if !ok {
return errors.NewError(errors.ErrInternal, "cannot scan event kind")
}
*k = EventKind(v)
return nil
}
// Value implements the driver.Valuer interface.
// Simply returns the string representation of the FunctionStatus.
func (fs *FunctionStatus) Value() (driver.Value, error) {
return fs.String(), nil
}
// Scan implements the sql.Scanner interface.
// Simply decodes a string into the FunctionStatus.
func (fs *FunctionStatus) Scan(value interface{}) error {
s, ok := value.(string)
if !ok {
return errors.NewInternal("cannot scan function status: invalid string")
}
v, ok := FunctionStatus_value[s]
if !ok {
return errors.NewInternal("cannot scan function status: unknown value")
}
*fs = FunctionStatus(v)
return nil
}
// Value implements the driver.Valuer interface.
// Simply returns the string representation of the FunctionStatus.
func (fak *FailedAssetKind) Value() (driver.Value, error) {
return fak.String(), nil
}
// Scan implements the sql.Scanner interface.
// Simply decodes a string into the FunctionStatus.
func (fak *FailedAssetKind) Scan(value interface{}) error {
s, ok := value.(string)
if !ok {
return errors.NewInternal("cannot scan failed asset kind: invalid string")
}
v, ok := FailedAssetKind_value[s]
if !ok {
return errors.NewInternal("cannot scan failed asset kind: unknown value")
}
*fak = FailedAssetKind(v)
return nil
}