File tree 3 files changed +15
-3
lines changed
3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change
1
+ github.com/friendsofgo/errors v0.9.2 h1:X6NYxef4efCBdwI7BgS820zFaN7Cphrmb+Pljdzjtgk =
1
2
github.com/friendsofgo/errors v0.9.2 /go.mod h1:yCvFW5AkDIL9qn7suHVLiI/gH228n7PC4Pn44IGoTOI =
3
+ github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE =
2
4
github.com/gofrs/uuid v3.2.0+incompatible /go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM =
3
5
github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU =
4
6
github.com/volatiletech/inflect v0.0.1 /go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA =
Original file line number Diff line number Diff line change @@ -109,6 +109,12 @@ func (u *Uint64) Scan(value interface{}) error {
109
109
return nil
110
110
}
111
111
u .Valid = true
112
+
113
+ // If value is negative int64, convert it to uint64
114
+ if i , ok := value .(int64 ); ok && i < 0 {
115
+ return convert .ConvertAssign (& u .Uint64 , uint64 (i ))
116
+ }
117
+
112
118
return convert .ConvertAssign (& u .Uint64 , value )
113
119
}
114
120
@@ -118,6 +124,7 @@ func (u Uint64) Value() (driver.Value, error) {
118
124
return nil , nil
119
125
}
120
126
127
+ // If u.Uint64 overflows the range of int64, convert it to string
121
128
if u .Uint64 >= 1 << 63 {
122
129
return strconv .FormatUint (u .Uint64 , 10 ), nil
123
130
}
Original file line number Diff line number Diff line change @@ -145,10 +145,13 @@ func TestUint64Scan(t *testing.T) {
145
145
maybePanic (err )
146
146
assertUint64 (t , i , "scanned uint64" )
147
147
148
- var null Uint64
149
- err = null .Scan (nil )
148
+ err = i .Scan (int64 (- 2 ))
149
+ maybePanic (err )
150
+ assertUint64 (t , i , "scanned int64" )
151
+
152
+ err = i .Scan (nil )
150
153
maybePanic (err )
151
- assertNullUint64 (t , null , "scanned null" )
154
+ assertNullUint64 (t , i , "scanned null" )
152
155
}
153
156
154
157
func assertUint64 (t * testing.T , i Uint64 , from string ) {
You can’t perform that action at this time.
0 commit comments