ozzo-dbx
ozzo-dbx copied to clipboard
How to get result assigned to a struct for array in array?
I have the following struct:
type Order struct {
OrderResourceID string `json:"orderResourceID" db:"orderResourceID"`
OrderStatusID int `json:"orderStatusID" db:"orderStatusID"`
ClientUsername string `json:"clientUsername" db:"clientUsername"`
ClientFullName string `json:"clientFullName" db:"clientFullName"`
ClientPhotoUrl string `json:"clientPhotoUrl" db:"clientPhotoUrl"`
OrderItems []OrderItem `json:"orderItems" db:"orderItems"`
}
type OrderItem struct {
ProductTitle string `json:"productTitle" db:"productTitle"`
ProductPrice int `json:"productPrice" db:"productPrice"`
ProductSize string `json:"productSize" db:"productSize"`
ProductSizePrice int `json:"productSizePrice" db:"productSizePrice"`
ProductExtra []ItemExtra `json:"productExtra" db:"productExtra"`
}
type ItemExtra struct {
ProductExtraTitle string `json:"productExtraTitle" db:"productExtraTitle"`
ProductExtraPrice int `json:"productExtraPrice" db:"productExtraPrice"`
}
How should database call look like to get it assigned to these slices?
Database returns json_array on the point of slices. And I get this error: Internal server error: sql: Scan error on column index 5: unsupported Scan, storing driver.Value type []uint8 into type *[]models.OrderItem"}.
I assign to the variable with .One(&order) method after query selection.
What to change so it would populate all arrays and that array of an array?
You should create a new slice type and implement the Scanner interface and/or Valuer interface.
Could you provide a short example? I'm not quite sure how to do it. @qiangxue