-
Notifications
You must be signed in to change notification settings - Fork 810
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
Ability to return an iterator on rows #3631
base: main
Are you sure you want to change the base?
Conversation
Thank you so much for the first pass on iterator support. Could you update your PR description with an example of how to use the |
Fixes #720 |
@kyleconroy |
@kyleconroy |
I found some example tests here https://github.com/sqlc-dev/sqlc/tree/main/examples and added iterator tests there |
@kyleconroy, hi |
I see that the stdlib sometimes uses the suffix Seq() to indicate methods that returns iterators. I suggest to think a bit more if Iterate() is the appropriate name for this functionality. |
|
I do not think the |
@gbarr, thanks for your comment
|
Instead of having an IterCities(ctx context.Context) (seq iter.Seq2[City, error], stop func()) Usage would be: func example(ctx context.Context, q *Queries) error {
rows, stop := q.IterCities(ctx)
defer stop()
for city, err := range rows {
if err != nil {
return err
}
// do something with city
}
return nil
} I think this is a bit cleaner than the above generated code, saving a whole new type for the iterator. |
I thought about such an interface, but I'm afraid that if the user uses range with one variable, the behavior will not match the expected one |
Example of generated query:
Example of use:
UPD: updated the code according to the latest changes