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

[+] add Kind() method to convert *Rows to pgx.Rows interface #168

Merged
merged 2 commits into from
Nov 2, 2023
Merged

[+] add Kind() method to convert *Rows to pgx.Rows interface #168

merged 2 commits into from
Nov 2, 2023

Conversation

labi-le
Copy link
Contributor

@labi-le labi-le commented Nov 1, 2023

Kind returns rows corresponding to the interface pgx.Rows
useful for testing entities that implement an interface pgx.RowScanner

example

package notifier

import (
	"github.com/go-faker/faker/v4"
	"github.com/jackc/pgx/v5"
	"github.com/pashagolub/pgxmock/v3"
	"testing"
)

var fixtureBench = func() pgx.Rows {
	mock, _ := pgxmock.NewPool()

	rows := mock.NewRows([]string{"id", "email", "name", "phone"})
	for i := 0; i < 100_000; i++ {
		rows.AddRow(i, faker.Email(), faker.Name(), faker.Phonenumber())
	}

	return rows.Kind()
}()

func BenchmarkAudience_ScanRow(b *testing.B) {
	b.ReportAllocs()
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		audience := &Audience{}
		err := audience.ScanRow(fixtureBench)
		if err != nil {
			b.Fatal(err)
		}
	}
}

@pashagolub pashagolub self-assigned this Nov 1, 2023
@pashagolub pashagolub added the enhancement New feature or request label Nov 2, 2023
@pashagolub
Copy link
Owner

Thanks for the pull request. Would you please add unit tests to cover the new function as well?

@labi-le
Copy link
Contributor Author

labi-le commented Nov 2, 2023

ready

@pashagolub pashagolub changed the title add Kind() method to convert *Rows to pgx.Rows interface [+] add Kind() method to convert *Rows to pgx.Rows interface Nov 2, 2023
@pashagolub
Copy link
Owner

Great! Thanks!

@pashagolub pashagolub merged commit 7f5256f into pashagolub:master Nov 2, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants