first of all: I am totally newbie in golang, so I may not understand well. I am tasked to write a Go data extractor from one database using "gorp". The problem is with one table, that has custom field "TimeRange". It is defined as:
type TimeRange struct {
From string
To string
}
Sadly when I try to fetch row I am getting scanner error, so I realised I need a custom scanner.
// Scan - Implement the database/sql scanner interface
func (tr *TimeRange) Scan(value interface{}) error {
tr.From = "mis"
tr.To = "lala"
fmt.Printf("%v\n", *tr)
return nil
}
So I expect to see fixed '{mis lala}' in returned string. Why I am getting:
var q2 []models.Dashboard
result, err := dbmap.Select(&q2, "select * from dashboard where id=3")
fmt.Printf("q2=%v\n", q2)
prints:
p2=[{{<nil> Tomek b1f6f0ba-f618-00d6-6d24-8410a9219c95}}]
which is: TimeRange, UserName and UUID
Might be important: using "gorp" for DB managment
the scan function would be called on passed value type to
dbmap.Select()
so in your case, you need to implementDashboard
asscanner
.