I am trying to use Struct and StructScan (sqlx), but no values are present. Only the struct.
type Hr struct {
hr_id int `db:"hr_id"`
hr_sign string `db:"hr_sign"`
hr_code string `db:"hr_code"`
hr_sum float64 `db:"hr_sum"`
}
func get(query string) interface{} {
if len(query) > 0 {
rows, err := db.Queryx("SELECT * FROM hr")
defer rows.Close()
fmt.Println(rows)
hr := Hr{}
for rows.Next() {
err := rows.StructScan(&hr)
if err != nil {
log("next error" + err.Error())
}
fmt.Printf("%#v\n", hr)
}
if err != nil {
log("get error" + err.Error())
}
return hr
}
return nil
}
The results ar empty:
main.Hr{hr_id:0, hr_sign:ββ, hr_code:ββ, hr_sum:0}
main.Hr{hr_id:0, hr_sign:ββ, hr_code:ββ, hr_sum:0}
And I get this error at log(βnext errorβ + err.Error()):
errormissing destination name hr_id in *main.Hr
What am I doing wrong?