pgx
pgx copied to clipboard
Scan not only anonymous structs
Why in pgx we don't scan non anonymous structs? For ex:
type Currency struct {
Code string `json:"code"`
IsHidden bool `json:"is_hidden"`
ImageURL string `json:"image_url"`
FriendlyName string `json:"friendly_name"`
}
type DetailedBalance struct {
UserID int64 `json:"user_id,omitempty"`
Currency Currency `json:"currency"`
Balance float64 `json:"balance"`
}
But it words with:
type DetailedBalance struct {
UserID int64 `json:"user_id,omitempty"`
Currency struct {
Code string `json:"code"`
IsHidden bool `json:"is_hidden"`
ImageURL string `json:"image_url"`
FriendlyName string `json:"friendly_name"`
}
Balance float64 `json:"balance"`
}
Is there any specific issues with this?
I believe that should work. But you would need a runnable example for anyone else to see exactly what it happening.
I will give tomorrow runnable example, forgot about it, ty for so fast response
@jackc
There are some code: https://go.dev/play/p/x-s1Iwg5ro2
IDK, but right now no one of variants are not working, maybe Im doing something wrong (its ~12pm right now)
But I was testing and anonymous structs were working and first variant was not working
Thanks for your attention
You also need to register any composite types. See TestCompositeCodecTranscodeStruct in the pgx source for an example.