go-rel / rel

:gem: Modern ORM for Golang - Testable, Extendable and Crafted Into a Clean and Elegant API
https://go-rel.github.io/
MIT License
762 stars 56 forks source link

Could not convert string into time #370

Open fairking opened 5 months ago

fairking commented 5 months ago

In one of my query I have the following error:

sql: Scan error on column index 0, name \"last_visited\": unsupported Scan, storing driver.Value type string into type *time.Time

I have reproduced the issue here: https://github.com/fairking/sql/commit/94d95e48b99def9a489b5a479f1fa899cc3f3eec

2024/04/18 03:10:34 [duration: 0s op: adapter-query] SELECT MAX(last_visited) last_visited FROM "users" GROUP BY "users"."gender";
    \go-rel\sqlite3\query.go:155:
                Error Trace:    /go-rel/sql/specs/query.go:155
                Error:          Expected nil, but got: &fmt.wrapError{msg:"sql: Scan error on column index 0, name \"last_visited\": unsupported Scan, storing driver.Value type string into type *time.Time", err:(*errors.errorString)(0xc0003ec6c0)}
                Test:           TestAdapter_specs/FindAll#35
--- FAIL: TestAdapter_specs/FindAll#35 (0.00s)

My struct:

type ContactItem struct {
    LastVisited *time.Time `json:"lastVisited"`
}

Any idea why that happen?

fairking commented 4 months ago

Stuck with this issue. Any queries with grouping and time involved do not work. :-(

fairking commented 3 months ago

I suspect because the date/time string does not contain timezone or ticks bits.

Fs02 commented 3 months ago

are you using sqlite? is the issue still happen if you use string in your struct?

if yes, then it's possibly related to this issue: https://github.com/mattn/go-sqlite3/issues/951