Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rows): doesn't close rows on Scan #49

Merged
merged 8 commits into from
Dec 12, 2024
1 change: 0 additions & 1 deletion rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (r *Rows) Close() error {
}

func (r *Rows) Scan(dest ...any) error {
defer r.Close()
return r.Rows.Scan(dest...)
}

Expand Down
34 changes: 34 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ func TestRowsBind(t *testing.T) {
name string
run func(t *testing.T)
}{
{
name: "scan_on_rows_should_work",
run: func(t *testing.T) {
type user struct {
ID int
Status int
Email string
Passwd string
Salt string
Created *time.Time
}
rows, err := db.Query("SELECT id,email FROM rows WHERE id<4")
require.NoError(t, err)

var id int
var email string

err = rows.Scan(&id, &email)
require.NoError(t, err)
require.Equal(t, 1, id)
require.Equal(t, "[email protected]", email)

err = rows.Scan(&id, &email)
require.NoError(t, err)
require.Equal(t, 2, id)
require.Equal(t, "[email protected]", email)

err = rows.Scan(&id, &email)
require.NoError(t, err)
require.Equal(t, 3, id)
require.Equal(t, "[email protected]", email)

},
},
{
name: "bind_slice_of_struct_should_work",
run: func(t *testing.T) {
Expand Down
Loading