Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,8 @@ func (t *Table[T, P, I]) Iter(ctx context.Context, where sq.Sqlizer, orderBy []s
defer rows.Close()
for rows.Next() {
var record T
if err := t.Query.Scan.ScanOne(&record, rows); err != nil {
if !errors.Is(err, pgx.ErrNoRows) {
yield(nil, err)
}
if err := t.Query.Scan.ScanRow(&record, rows); err != nil {
yield(nil, err)
return
}
if !yield(&record, nil) {
Expand Down
28 changes: 28 additions & 0 deletions tests/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,34 @@ func TestHardDeleteByID(t *testing.T) {
})
}

func TestIter(t *testing.T) {
truncateAllTables(t)

ctx := t.Context()
db := initDB(DB)

account := &Account{Name: "Iter Account"}
err := db.Accounts.Insert(ctx, account)
require.NoError(t, err)

const total = 100
for i := range total {
err := db.Articles.Insert(ctx, &Article{AccountID: account.ID, Author: fmt.Sprintf("Author %03d", i)})
require.NoError(t, err)
}

iter, err := db.Articles.Iter(ctx, sq.Eq{"account_id": account.ID}, []string{"id"})
require.NoError(t, err)

var count int
for article, err := range iter {
require.NoError(t, err)
require.NotNil(t, article)
count++
}
require.Equal(t, total, count, "Iter should yield all rows")
}

func TestLockForUpdates(t *testing.T) {
truncateAllTables(t)

Expand Down
Loading