go-ozzo / ozzo-dbx

A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.
MIT License
636 stars 91 forks source link

How to get JSON from MySql? #81

Open kolkov opened 5 years ago

kolkov commented 5 years ago

Hi! How can I get json from MySql to my model struct? Is this possible?

type Cargo struct {
    Id int64 `json:"id"`
    CompanyId int64 `json:"companyId"`
    ShipperId int64 `json:"shipperId"`
    ConsigneeId int64 `json:"consigneeId"`
    ConsigneeContacts ConsigneeContacts `json:"consigneeContacts"`
    Type int
    ShippingName string `json:"shippingName"`
    ReceiptNumber int `json:"receiptNumber"`
    IncomingDate null.Time `json:"incomingDate"`
    PackagesNumber int `json:"packagesNumber"`
    Volume float64 `json:"volume"`
    Weight float32 `json:"weight"`
    Status string `json:"status"`
    WaggonObservedId int `json:"waggonObservedId"`
    Note string `json:"'note'"`
    CreatorId int `json:"creatorId"`
    CreatedAt null.Time `json:"createdAt"`
}

type ConsigneeContacts struct {
    Phones []string `json:"phones"`
    Emails []string `json:"emails"`
}

{"emails": ["a.aaa@aaa.com"], "phones": ["9161234567"]}

Thanks!