sqlx missing destination name with MySQL

496 Views Asked by At

I have a query which returns result of mysql json_object function. But when I try to call my api I got an error

missing destination name json_object('id', vd.id, 'title', vd.title...

type Vacancies struct {
    ID int `json:"id"`
    Title string `json:"title"`
    Logo string `json:"logo"`
    Items []string `json:"items"`
}

func (r *repository) GetVacancies(ctx context.Context) []*Vacancies {
    const queryString = "select json_object('id', vd.id, 'title', vd.title, 'logo', vd.logo, 'items', json_array((select GROUP_CONCAT(json_object('id', id, 'title', title, 'description', description)) from vacancies as v where department_id = vd.id order by vd.sort))) from vacancy_departments as vd order by vd.sort"
    defer utils.StartRelicDatastoreSegment(
        ctx, newrelic.DatastoreMySQL, "Vacancies.GetVacancies", "Select", queryString,
    ).End()

    var result []*Vacancies
    if err := mysql.Client().Slave().Select(&result, queryString); err != nil {
        logger.Get().Error("err while getting vacancies", zap.Error(err))
        return nil
    }

    return result
}

How is it possible to get valid data for golang structure?

0

There are 0 best solutions below