Skip to content

Commit

Permalink
Check rows.Err
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed May 17, 2021
1 parent 01a7183 commit 8d804e4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/dbtest/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func testScanSingleRowByRow(t *testing.T, db *bun.DB) {

nums = append(nums, num)
}
require.NoError(t, rows.Err())

require.Equal(t, []int{3, 2, 1}, nums)
}
Expand Down
3 changes: 3 additions & 0 deletions model_map_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func (m *mapSliceModel) ScanRows(ctx context.Context, rows *sql.Rows) (int, erro
slice = append(slice, m.m)
n++
}
if err := rows.Err(); err != nil {
return 0, err
}

*m.slicePtr = slice
return n, nil
Expand Down
3 changes: 3 additions & 0 deletions model_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (m *sliceModel) ScanRows(ctx context.Context, rows *sql.Rows) (int, error)
}
n++
}
if err := rows.Err(); err != nil {
return 0, err
}

return n, nil
}
Expand Down
3 changes: 3 additions & 0 deletions model_table_has_many.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func (m *hasManyModel) ScanRows(ctx context.Context, rows *sql.Rows) (int, error

n++
}
if err := rows.Err(); err != nil {
return 0, err
}

return n, nil
}
Expand Down
3 changes: 3 additions & 0 deletions model_table_m2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func (m *m2mModel) ScanRows(ctx context.Context, rows *sql.Rows) (int, error) {

n++
}
if err := rows.Err(); err != nil {
return 0, err
}

return n, nil
}
Expand Down
3 changes: 3 additions & 0 deletions model_table_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func (m *sliceTableModel) ScanRows(ctx context.Context, rows *sql.Rows) (int, er

n++
}
if err := rows.Err(); err != nil {
return 0, err
}

return n, nil
}
Expand Down

0 comments on commit 8d804e4

Please sign in to comment.