Skip to content

Feature Request: SQL Query result as map, rather than slice/array #728

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

Closed
StevenACoffman opened this issue Oct 9, 2020 · 4 comments
Closed
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@StevenACoffman
Copy link
Contributor

StevenACoffman commented Oct 9, 2020

We have queries that returns a large number of rows, which we immediately convert into a map, keyed by one of the returned row's fields.

For both convenience and performance reasons would like the return type of these :many query to be a keyed map instead of a slice/array. Is there anyway to hint sqlc to emit a slightly different generated boilerplate to achieve this? Possibly something like having our SQL query :map hint that would cause generated results to be returned as as a Go map (keyed by first field) instead of slice.

As a workaround, we can alter our PostgreSQL queries to select into constructed hstore values like this:

create table dir (myID text, value_string text);
insert into dir values
('MY_ID', 1),
('ACC', 2);

select hstore(array_agg(MY_ID), array_agg(value_string))
from dir;

         hstore          
-------------------------
 "ACC"=>"2", "MY_ID"=>"1"
(1 row)
@StevenACoffman StevenACoffman changed the title SQL Query result as map, rather than slice/array Feature Request: SQL Query result as map, rather than slice/array Oct 9, 2020
@kyleconroy kyleconroy added enhancement New feature or request wontfix This will not be worked on labels Oct 19, 2020
@kyleconroy
Copy link
Collaborator

@StevenACoffman thanks for the feature request! I have less time right now to focus on sqlc, so I'm only going to be working on the highest priority issues, which is currently MySQL support. I hope to eventually have a plugin system so that you could write :map yourself, but for now I'm going to close this one out.

@StevenACoffman
Copy link
Contributor Author

Entirely understandable. Would you be open to a pull request at this point?

@ChielTimmermans
Copy link

@kyleconroy is there any possibily for me or @StevenACoffman to write a PR to add this as an enhancement?

@juanmartin8a
Copy link

#2353

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants