File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,11 +11,7 @@ type Bool bool
1111// Value implements the driver.Valuer interface,
1212// and turns the BitBool into a bit field (BIT(1)) for MySQL storage.
1313func (b Bool ) Value () (driver.Value , error ) { // skipcq: GO-W1029
14- if b {
15- return []byte {1 }, nil
16- } else {
17- return []byte {0 }, nil
18- }
14+ return bool (b ), nil
1915}
2016
2117// Scan implements the sql.Scanner interface,
@@ -30,6 +26,14 @@ func (b *Bool) Scan(src interface{}) error { // skipcq: GO-W1029
3026 * b = v [0 ] == 1
3127 case int64 :
3228 * b = v == 1
29+ case bool :
30+ * b = Bool (v )
31+ case string :
32+ if v == "1" || v == "t" || v == "T" || v == "true" || v == "TRUE" || v == "True" {
33+ * b = true
34+ } else {
35+ * b = false
36+ }
3337 default :
3438 return errors .New ("bad []byte type assertion" )
3539 }
Original file line number Diff line number Diff line change @@ -48,6 +48,11 @@ func TestBool(t *testing.T) {
4848
4949 require .EqualValues (t , true , b1 )
5050
51+ err = d .QueryRow ("SELECT `status` FROM `users` WHERE id=? AND status=1" , 10 ).Scan (& b1 )
52+ require .NoError (t , err )
53+
54+ require .EqualValues (t , true , b1 )
55+
5156 var b2 Bool
5257 err = d .QueryRow ("SELECT `status` FROM `users` WHERE id=?" , 11 ).Scan (& b2 )
5358 require .NoError (t , err )
You can’t perform that action at this time.
0 commit comments