Skip to content

[proposal] :map key=somefield query annotation #2353

Open
@Jille

Description

@Jille

What do you want to change?

I frequently find myself converting the results from a query to a map, keyed by one of the fields. The code looks like this:

m := map[string]gendb.User{}
users, err := gendb.QueryUsers(ctx)
for _, u := range users {
  m[u.Username] = u
}

I've been holding off on this feature request hoping that generics would cleanly solve this, but solutions with generics aren't as pretty as I'd hoped. (Using a Map plus a lambda to return a field.)

Given that sqlc has all the information needed for this, it would be a neat convenience if sqlc could generate this boilerplate for me :)

I'm willing to send a PR if approved.

What database engines need to be changed?

No response

What programming language backends need to be changed?

Go

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions