Firstly, I've tried solutions from past stackoverflow answers whose questions were related to mine, and nothing has worked, that's why i am asking it as a separate question.
I have two structs in golang
type otherPayments struct {
DebitTo int `json:"debit_To" binding:"required"`
CreditFrom int `json:"credit_from" binding:"required"`
OverallType string `json:"overall_type" binding:"required"`
}
type advanceAndRoomPayment struct {
PmID int `json:"pm_id" binding:"required"` //Payment method id
PmName string `json:"pm_name" binding:"required"` //Payment method name
DebitTo int `json:"debit_To" binding:"required"` //The ledger to debit from
CreditFrom int `json:"credit_from" binding:"required"` //The ledger to credit from
OverallType string `json:"overall_type" binding:"required"` //Overall transaction type
}
And i have 5 SQL columns within my booking_settings postgresql table
initialcolumn, type =otherPayments,JSONBcancellation, type =otherPayments,JSONBupdation, type =otherPayments,JSONBadvance_paymenttype =advanceAndRoomPayment,JSONB []room_payment, type =advanceAndRoomPayment,JSONB []
The SELECT query is as follows
SELECT initial, cancellation, updation advance_payment, room_payment FROM booking_settings WHERE hotel_id = $1
The sql package i am using is https://jmoiron.github.io/sqlx/
I am trying to scan above columns into their appropriate struct vars, so far i could only manage to scan initial, cancellation and updation but not the JSONB [] advance_payment and room_payment
Any help is really appreciated, thank you
sqlx, but with the stdlib's package, you simply declare a named go-type that corresponds to the db-column's type, or its contents if it's something dynamic likejsonb. Then you implement thesql.Scannerinterface on the newly declared named go-type to handle the custom unmarshaling of the db-value into the go-value.JSONBobject, but i am unable to implement that function when i have an array of jsonbJSONB []jsonb[]intoadvanceAndRoomPayment? or into[]advanceAndRoomPayment? Also what is the error you're getting?[]and also some byte[] conversion error, if you know how to properly implement that function, i would highly appreciate an implementation as answer :)