1
1
package sql
2
2
3
3
import (
4
+ "database/sql/driver"
4
5
"fmt"
5
6
"reflect"
6
7
"strconv"
@@ -43,6 +44,7 @@ type Type interface {
43
44
Check (interface {}) bool
44
45
Convert (interface {}) (interface {}, error )
45
46
Compare (interface {}, interface {}) int
47
+ Native (interface {}) driver.Value
46
48
}
47
49
48
50
var Null = nullType {}
@@ -75,6 +77,10 @@ func (t nullType) Compare(a interface{}, b interface{}) int {
75
77
return 0
76
78
}
77
79
80
+ func (t nullType ) Native (v interface {}) driver.Value {
81
+ return driver .Value (nil )
82
+ }
83
+
78
84
var Integer = integerType {}
79
85
80
86
type integerType struct {}
@@ -99,6 +105,10 @@ func (t integerType) Compare(a interface{}, b interface{}) int {
99
105
return compareInt32 (a , b )
100
106
}
101
107
108
+ func (t integerType ) Native (v interface {}) driver.Value {
109
+ return driver .Value (int64 (v .(int32 )))
110
+ }
111
+
102
112
var BigInteger = bigIntegerType {}
103
113
104
114
type bigIntegerType struct {}
@@ -123,6 +133,10 @@ func (t bigIntegerType) Compare(a interface{}, b interface{}) int {
123
133
return compareInt64 (a , b )
124
134
}
125
135
136
+ func (t bigIntegerType ) Native (v interface {}) driver.Value {
137
+ return driver .Value (v .(int64 ))
138
+ }
139
+
126
140
// TimestampWithTimezone is a timestamp with timezone.
127
141
var TimestampWithTimezone = timestampWithTimeZoneType {}
128
142
@@ -148,6 +162,10 @@ func (t timestampWithTimeZoneType) Compare(a interface{}, b interface{}) int {
148
162
return compareTimestamp (a , b )
149
163
}
150
164
165
+ func (t timestampWithTimeZoneType ) Native (v interface {}) driver.Value {
166
+ return driver .Value (v .(time.Time ))
167
+ }
168
+
151
169
var String = stringType {}
152
170
153
171
type stringType struct {}
@@ -172,6 +190,10 @@ func (t stringType) Compare(a interface{}, b interface{}) int {
172
190
return compareString (a , b )
173
191
}
174
192
193
+ func (t stringType ) Native (v interface {}) driver.Value {
194
+ return driver .Value (v .(string ))
195
+ }
196
+
175
197
var Boolean Type = booleanType {}
176
198
177
199
type booleanType struct {}
@@ -196,6 +218,10 @@ func (t booleanType) Compare(a interface{}, b interface{}) int {
196
218
return compareBool (a , b )
197
219
}
198
220
221
+ func (t booleanType ) Native (v interface {}) driver.Value {
222
+ return driver .Value (v .(bool ))
223
+ }
224
+
199
225
var Float Type = floatType {}
200
226
201
227
type floatType struct {}
@@ -220,6 +246,10 @@ func (t floatType) Compare(a interface{}, b interface{}) int {
220
246
return compareFloat64 (a , b )
221
247
}
222
248
249
+ func (t floatType ) Native (v interface {}) driver.Value {
250
+ return driver .Value (v .(float64 ))
251
+ }
252
+
223
253
func checkString (v interface {}) bool {
224
254
_ , ok := v .(string )
225
255
return ok
0 commit comments