I am trying to query objects from sqlite but getting this error because of the type time:
(sql: Scan error on column index 1: unsupported Scan, storing driver.Value type []uint8 into type *time.Time)
my struct is:
type Timeline struct {
ID string `json:"id"`
Timestamp *time.Time `json:"timestamp"`
and my database is like this:
CREATE TABLE timelines (id text, timestamp text, ...
and one of the sample rows is:
('Locked in VR', '2018-03-17 10:50:59.548+01:00',...
any ideas? should I have something in the struct like?
Timestamp *time.Time `json:"timestamp" gorm:"time"`
Using this would take care of it:
You could even change the declared type of the
Timestamp
field to something else, sayint64
to represent Unix times. Then you could write a Scanner to read the datetime field into the int64 field.I am not familiar with gorm, but should not the definition of timestamp of type
datetime
instead oftext
? Also: when you taggorm:"time"
the column name should betime
and nottimestamp
, or the taggorm:"timestamp"
. But you can leave out the gorm tag.To make it simple, you can let gorm create the table: