forked from xo/xo
/
aenum.xo.go
95 lines (81 loc) · 1.96 KB
/
aenum.xo.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
package mysql
// Code generated by xo. DO NOT EDIT.
import (
"database/sql/driver"
"fmt"
)
// AEnum is the 'a_enum' enum type from schema 'a_bit_of_everything'.
type AEnum uint16
// AEnum values.
const (
// AEnumOne is the 'ONE' a_enum.
AEnumOne AEnum = 1
// AEnumTwo is the 'TWO' a_enum.
AEnumTwo AEnum = 2
)
// String satisfies the fmt.Stringer interface.
func (ae AEnum) String() string {
switch ae {
case AEnumOne:
return "ONE"
case AEnumTwo:
return "TWO"
}
return fmt.Sprintf("AEnum(%d)", ae)
}
// MarshalText marshals AEnum into text.
func (ae AEnum) MarshalText() ([]byte, error) {
return []byte(ae.String()), nil
}
// UnmarshalText unmarshals AEnum from text.
func (ae *AEnum) UnmarshalText(buf []byte) error {
switch str := string(buf); str {
case "ONE":
*ae = AEnumOne
case "TWO":
*ae = AEnumTwo
default:
return ErrInvalidAEnum(str)
}
return nil
}
// Value satisfies the driver.Valuer interface.
func (ae AEnum) Value() (driver.Value, error) {
return ae.String(), nil
}
// Scan satisfies the sql.Scanner interface.
func (ae *AEnum) Scan(v interface{}) error {
if buf, ok := v.([]byte); ok {
return ae.UnmarshalText(buf)
}
return ErrInvalidAEnum(fmt.Sprintf("%T", v))
}
// NullAEnum represents a null 'a_enum' enum for schema 'a_bit_of_everything'.
type NullAEnum struct {
AEnum AEnum
// Valid is true if AEnum is not null.
Valid bool
}
// Value satisfies the driver.Valuer interface.
func (nae NullAEnum) Value() (driver.Value, error) {
if !nae.Valid {
return nil, nil
}
return nae.AEnum.Value()
}
// Scan satisfies the sql.Scanner interface.
func (nae *NullAEnum) Scan(v interface{}) error {
if v == nil {
nae.AEnum, nae.Valid = 0, false
return nil
}
err := nae.AEnum.Scan(v)
nae.Valid = err == nil
return err
}
// ErrInvalidAEnum is the invalid AEnum error.
type ErrInvalidAEnum string
// Error satisfies the error interface.
func (err ErrInvalidAEnum) Error() string {
return fmt.Sprintf("invalid AEnum(%s)", string(err))
}