-
Notifications
You must be signed in to change notification settings - Fork 804
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
[proposal] :map key=somefield
query annotation
#2353
Labels
Comments
Jille
added
enhancement
New feature or request
triage
New issues that hasn't been reviewed
labels
Jun 21, 2023
kyleconroy
added
proposal
and removed
triage
New issues that hasn't been reviewed
labels
Jun 21, 2023
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 25, 2023
Like `-- name: InsertMulti :exec multiple` and `-- name: Select :many key=group_id` issue sqlc-dev#2353
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 25, 2023
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 28, 2023
Like `-- name: InsertMulti :exec multiple` and `-- name: Select :many key=group_id` issue sqlc-dev#2353
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 28, 2023
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 28, 2023
Like `-- name: InsertMulti :exec multiple` and `-- name: Select :many key=group_id` issue sqlc-dev#2353
This was referenced Jun 28, 2023
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 28, 2023
Like `-- name: InsertMulti :exec multiple` and `-- name: Select :many key=group_id` issue sqlc-dev#2353
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 28, 2023
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 28, 2023
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 28, 2023
Jille
added a commit
to Jille/sqlc
that referenced
this issue
Jun 28, 2023
What about also adding an option to allow multiple values per key? So instead of While not as common as the case with one value per key, I still sometimes find myself implementing this. |
Another way of solving the problem:
-- name: listXX :many
select * from xx func (q *Queries) listXX(ctx context.Context) ([]SomeStruct, error)
func (q *Queries) ListXX(ctx context.Context) (map[string]SomeStruct, error) {
s, _ := q.listXX(ctx)
m := make(map[string]SomeStruct)
for _, u := range s {
m[u.SomeColumn] = u
}
return m, nil
} Pros:
Cons:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
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
The text was updated successfully, but these errors were encountered: