-
Notifications
You must be signed in to change notification settings - Fork 0
/
int_ptr.go
130 lines (105 loc) · 1.91 KB
/
int_ptr.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
package parser
import (
"database/sql/driver"
"fmt"
)
func toInt16Ptr(i int16) *int16 {
return &i
}
func toIntPtr(i int) *int {
return &i
}
func toInt32Ptr(i int32) *int32 {
return &i
}
func toInt64Ptr(i int64) *int64 {
return &i
}
type IntPtr struct {
i *int
}
type Int16Ptr struct {
i *int16
}
type Int32Ptr struct {
i *int32
}
type Int64Ptr struct {
i *int64
}
func (p IntPtr) Value() (driver.Value, error) {
return p.i, nil
}
func (p *IntPtr) Scan(value interface{}) error {
if value == nil {
p.i = nil
return nil
}
if bv, err := driver.Int32.ConvertValue(value); err != nil {
if v, ok := bv.(int); ok {
*p = IntPtr{
i: toIntPtr(v),
}
}
} else {
return fmt.Errorf("failed to scan IntPtr:\n%v", err)
}
return nil
}
func (p Int32Ptr) Value() (driver.Value, error) {
return p.i, nil
}
func (p *Int32Ptr) Scan(value interface{}) error {
if value == nil {
p.i = nil
return nil
}
if bv, err := driver.Int32.ConvertValue(value); err != nil {
if v, ok := bv.(int32); ok {
*p = Int32Ptr{
i: toInt32Ptr(v),
}
}
} else {
return fmt.Errorf("failed to scan Int32Ptr:\n%v", err)
}
return nil
}
func (p Int64Ptr) Value() (driver.Value, error) {
return p.i, nil
}
func (p *Int64Ptr) Scan(value interface{}) error {
if value == nil {
p.i = nil
return nil
}
if bv, err := driver.Int32.ConvertValue(value); err != nil {
if v, ok := bv.(int64); ok {
*p = Int64Ptr{
i: toInt64Ptr(v),
}
}
} else {
return fmt.Errorf("failed to scan Int64Ptr:\n%v", err)
}
return nil
}
func (p Int16Ptr) Value() (driver.Value, error) {
return p.i, nil
}
func (p *Int16Ptr) Scan(value interface{}) error {
if value == nil {
p.i = nil
return nil
}
if bv, err := driver.Int32.ConvertValue(value); err != nil {
if v, ok := bv.(int16); ok {
*p = Int16Ptr{
i: toInt16Ptr(v),
}
}
} else {
return fmt.Errorf("failed to scan Int16Ptr:\n%v", err)
}
return nil
}