-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbinder_map.go
163 lines (152 loc) · 2.54 KB
/
binder_map.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
package sqle
import (
"database/sql"
"reflect"
"time"
)
type mapBinder struct {
elem any
}
// skipcq: GO-R1005
func (b *mapBinder) Bind(_ reflect.Value, columns []string) []any {
values := make([]any, len(columns))
switch b.elem.(type) {
case *int:
for i := range columns {
var it int
values[i] = &it
}
case *int8:
for i := range columns {
var it int8
values[i] = &it
}
case *int16:
for i := range columns {
var it int16
values[i] = &it
}
case *int32:
for i := range columns {
var it int32
values[i] = &it
}
case *int64:
for i := range columns {
var it int64
values[i] = &it
}
case *uint:
for i := range columns {
var it uint
values[i] = &it
}
case *uint8:
for i := range columns {
var it uint8
values[i] = &it
}
case *uint16:
for i := range columns {
var it uint16
values[i] = &it
}
case *uint32:
for i := range columns {
var it uint32
values[i] = &it
}
case *uint64:
for i := range columns {
var it uint64
values[i] = &it
}
case *uintptr:
for i := range columns {
var it uintptr
values[i] = &it
}
case *float32:
for i := range columns {
var it float32
values[i] = &it
}
case *float64:
for i := range columns {
var it float64
values[i] = &it
}
case *bool:
for i := range columns {
var it bool
values[i] = &it
}
case *string:
for i := range columns {
var it string
values[i] = &it
}
case *time.Time:
for i := range columns {
var it time.Time
values[i] = &it
}
case *sql.NullInt32:
for i := range columns {
it := &sql.NullInt16{}
values[i] = &it
}
case *sql.NullInt64:
for i := range columns {
it := &sql.NullInt64{}
values[i] = &it
}
case *sql.NullFloat64:
for i := range columns {
it := &sql.NullFloat64{}
values[i] = &it
}
case *sql.NullBool:
for i := range columns {
it := &sql.NullBool{}
values[i] = &it
}
case *sql.NullString:
for i := range columns {
it := &sql.NullString{}
values[i] = &it
}
case *sql.NullTime:
for i := range columns {
it := &sql.NullTime{}
values[i] = &it
}
default:
for i := range columns {
var it interface{}
values[i] = &it
}
}
return values
}
func getMapBinder(t reflect.Type, _ reflect.Type) Binder {
bindersMu.RLock()
var b Binder
var cached bool
defer func() {
bindersMu.RUnlock()
if !cached {
bindersMu.Lock()
binders[t] = b
bindersMu.Unlock()
}
}()
b, cached = binders[t]
if cached {
return b
}
b = &mapBinder{
elem: reflect.New(t.Elem()).Interface(),
}
return b
}