Skip to content

Commit

Permalink
fix(bool): renamed BitBool with Bool
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlangzi committed Apr 26, 2024
1 parent 2b5542e commit 328fae8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions bitbool.go → bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"errors"
)

// BitBool is an implementation of a bool for the MySQL type BIT(1).
type BitBool bool
// Bool is an implementation of a bool for the MySQL type BIT(1).
type Bool bool

// Value implements the driver.Valuer interface,
// and turns the BitBool into a bit field (BIT(1)) for MySQL storage.
func (b BitBool) Value() (driver.Value, error) { // skipcq: GO-W1029
func (b Bool) Value() (driver.Value, error) { // skipcq: GO-W1029
if b {
return []byte{1}, nil
} else {
Expand All @@ -20,7 +20,7 @@ func (b BitBool) Value() (driver.Value, error) { // skipcq: GO-W1029

// Scan implements the sql.Scanner interface,
// and turns the bit field incoming from MySQL into a BitBool
func (b *BitBool) Scan(src interface{}) error { // skipcq: GO-W1029
func (b *Bool) Scan(src interface{}) error { // skipcq: GO-W1029
if src == nil {
return nil
}
Expand Down
14 changes: 7 additions & 7 deletions bitbool_test.go → bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import (
"github.com/stretchr/testify/require"
)

func TestBitBool(t *testing.T) {
func TestBool(t *testing.T) {
d, err := sql.Open("sqlite3", "file::memory:")
require.NoError(t, err)

_, err = d.Exec("CREATE TABLE `users` (`id` id NOT NULL,`status` BIT(1), PRIMARY KEY (`id`))")
require.NoError(t, err)

result, err := d.Exec("INSERT INTO `users`(`id`, `status`) VALUES(?, ?)", 10, BitBool(true))
result, err := d.Exec("INSERT INTO `users`(`id`, `status`) VALUES(?, ?)", 10, Bool(true))
require.NoError(t, err)

rows, err := result.RowsAffected()
require.NoError(t, err)
require.Equal(t, int64(1), rows)

result, err = d.Exec("INSERT INTO `users`(`id`, `status`) VALUES(?, ?)", 11, BitBool(false))
result, err = d.Exec("INSERT INTO `users`(`id`, `status`) VALUES(?, ?)", 11, Bool(false))
require.NoError(t, err)

rows, err = result.RowsAffected()
Expand All @@ -42,25 +42,25 @@ func TestBitBool(t *testing.T) {
require.NoError(t, err)
require.Equal(t, int64(1), rows)

var b1 BitBool
var b1 Bool
err = d.QueryRow("SELECT `status` FROM `users` WHERE id=?", 10).Scan(&b1)
require.NoError(t, err)

require.EqualValues(t, true, b1)

var b2 BitBool
var b2 Bool
err = d.QueryRow("SELECT `status` FROM `users` WHERE id=?", 11).Scan(&b2)
require.NoError(t, err)

require.EqualValues(t, false, b2)

var b3 BitBool
var b3 Bool
err = d.QueryRow("SELECT `status` FROM `users` WHERE id=?", 12).Scan(&b3)
require.NoError(t, err)

require.EqualValues(t, true, b3)

var b4 BitBool
var b4 Bool
err = d.QueryRow("SELECT `status` FROM `users` WHERE id=?", 13).Scan(&b4)
require.NoError(t, err)

Expand Down

0 comments on commit 328fae8

Please sign in to comment.