I have a Postgres query that queries all data from table a while creating a JSON array from columns in table b.
E.g.:
SELECT
a.a_id,
a.column1,
COALESCE(
json_agg(
json_build_object(
'b-bid', b.b_id,
'b-name' , b.name,
)
) FILTER (WHERE b.a_id IS NOT NULL),
'[]'
)::json AS b_data
FROM
a
LEFT JOIN
b
ON
a.a_id = b.a_id
WHERE
a.column1 = $1
GROUP BY
a.aid;
The corresponding sqlc structure looks like this:
type GetAByIdRow struct {
AId uuid.UUID `json:"a_id"`
Column1 pgtype.Text `json:"column1"`
BData []byte `json:"b_data"`
}
How do I configure sqlc to emit structs of []B instead of []byte?
I tried sqlc.embed which creates a single struct of another table. I need a slice.
I also tried overriding types. It doesn't work as it's only meant for a column(or type) where as I'm running a join here.
My expected output:
type GetAByIdRow struct {
Aid uuid.UUID `json:"a_id"`
Column1 pgtype.Text `json:"column1"`
BData []B `json:"b_data"`
}
I appreciate any help you can give me. Thanks!