You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
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
@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.
Uh oh!
There was an error while loading. Please reload this page.
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:
The text was updated successfully, but these errors were encountered: