forked from abice/go-enum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_str_enum.go
More file actions
159 lines (141 loc) · 3.44 KB
/
sql_str_enum.go
File metadata and controls
159 lines (141 loc) · 3.44 KB
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
// Code generated by go-enum DO NOT EDIT.
// Version: example
// Revision: example
// Build Date: example
// Built By: example
package example
import (
"database/sql/driver"
"errors"
"fmt"
)
const (
// JobStatePending is a JobState of type Pending.
JobStatePending JobState = iota
// JobStateProcessing is a JobState of type Processing.
JobStateProcessing
// JobStateCompleted is a JobState of type Completed.
JobStateCompleted
// JobStateFailed is a JobState of type Failed.
JobStateFailed
)
const _JobStateName = "pendingprocessingcompletedfailed"
var _JobStateMap = map[JobState]string{
JobStatePending: _JobStateName[0:7],
JobStateProcessing: _JobStateName[7:17],
JobStateCompleted: _JobStateName[17:26],
JobStateFailed: _JobStateName[26:32],
}
// String implements the Stringer interface.
func (x JobState) String() string {
if str, ok := _JobStateMap[x]; ok {
return str
}
return fmt.Sprintf("JobState(%d)", x)
}
var _JobStateValue = map[string]JobState{
_JobStateName[0:7]: JobStatePending,
_JobStateName[7:17]: JobStateProcessing,
_JobStateName[17:26]: JobStateCompleted,
_JobStateName[26:32]: JobStateFailed,
}
// ParseJobState attempts to convert a string to a JobState
func ParseJobState(name string) (JobState, error) {
if x, ok := _JobStateValue[name]; ok {
return x, nil
}
return JobState(0), fmt.Errorf("%s is not a valid JobState", name)
}
var _JobStateErrNilPtr = errors.New("value pointer is nil") // one per type for package clashes
// Scan implements the Scanner interface.
func (x *JobState) Scan(value interface{}) (err error) {
if value == nil {
*x = JobState(0)
return
}
// A wider range of scannable types.
// driver.Value values at the top of the list for expediency
switch v := value.(type) {
case int64:
*x = JobState(v)
case string:
*x, err = ParseJobState(v)
case []byte:
*x, err = ParseJobState(string(v))
case JobState:
*x = v
case int:
*x = JobState(v)
case *JobState:
if v == nil {
return _JobStateErrNilPtr
}
*x = *v
case uint:
*x = JobState(v)
case uint64:
*x = JobState(v)
case *int:
if v == nil {
return _JobStateErrNilPtr
}
*x = JobState(*v)
case *int64:
if v == nil {
return _JobStateErrNilPtr
}
*x = JobState(*v)
case float64: // json marshals everything as a float64 if it's a number
*x = JobState(v)
case *float64: // json marshals everything as a float64 if it's a number
if v == nil {
return _JobStateErrNilPtr
}
*x = JobState(*v)
case *uint:
if v == nil {
return _JobStateErrNilPtr
}
*x = JobState(*v)
case *uint64:
if v == nil {
return _JobStateErrNilPtr
}
*x = JobState(*v)
case *string:
if v == nil {
return _JobStateErrNilPtr
}
*x, err = ParseJobState(*v)
}
return
}
// Value implements the driver Valuer interface.
func (x JobState) Value() (driver.Value, error) {
return x.String(), nil
}
type NullJobState struct {
JobState JobState
Valid bool
}
func NewNullJobState(val interface{}) (x NullJobState) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Scan implements the Scanner interface.
func (x *NullJobState) Scan(value interface{}) (err error) {
if value == nil {
x.JobState, x.Valid = JobState(0), false
return
}
err = x.JobState.Scan(value)
x.Valid = (err == nil)
return
}
// Value implements the driver Valuer interface.
func (x NullJobState) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
return x.JobState.String(), nil
}