Skip to content

WIP: Select() using iterator#990

Open
YuriyNasretdinov wants to merge 1 commit into
jmoiron:masterfrom
YuriyNasretdinov:sqlx_iterator
Open

WIP: Select() using iterator#990
YuriyNasretdinov wants to merge 1 commit into
jmoiron:masterfrom
YuriyNasretdinov:sqlx_iterator

Conversation

@YuriyNasretdinov

Copy link
Copy Markdown

Hi, given the recent proposal for generic methods being accepted into Go (golang/go#77273) I'd like to propose an interator API for Select() which looks like this:

for u, err := db.SelectIter[User]("SELECT * FROM users") {
    if err != nil { ... }
    ...
}

This API allows to have convenience of Select() without having to pre-allocate the entire result. The use-case is kinda niche, but without generic methods all other options look much uglier (example: https://github.com/YuriyNasretdinov/sqly).

The code works, however I'm happy to hear your feedback. Marked as WIP since I'd like to add more tests and, crucially, Go 1.27 isn't out yet. The tests do pass on gotip though, no GOEXPERIMENT needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant