We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is your feature request related to a problem? Please describe.
I have a struct with a custom time type CustomDateTime. I use it over time.Time because I change the way how it is stringified in json.
CustomDateTime
time.Time
type CustomDateTime time.Time type Log struct { Timestamp CustomDateTime `json:"timestamp" ch:"timestamp"` Field1 string `json:"field1" ch:"field1"` Field2 string `json:"field2" ch:"field2"` }
However, I get an error with this code:
var vv Log _ = conn.Select(ctx, &vv, dest, args...)
query error: clickhouse [ScanRow]: (timestamp) converting DateTime to *CustomDateTime is unsupported
When the using sql driver, I have no problem using DateTime column type to a struct field with type CustomDateTime.
sql
DateTime
Describe the solution you'd like
I want the same usage when I was using the sql driver.
var vv Log _ = conn.Select(ctx, &vv, dest)
I think #720 is a good reference for the solution.
Describe alternatives you've considered My alternative solution is to create a temporary alias struct and use row scan.
type logTmp struct { Log Timestamp `ch:"timestamp"` } rows, _ := db.conn.Query(....) var vv []Log for rows.Next() { var res postbackLogs if err := rows.ScanStruct(&res); err != nil { return nil, errors.WrapT(span, err, "scan error") } v := res.PostbackResult // unsupported types by the native driver must be converted by hand. v.Timestsamp = parseTimeToCustomDateTimeFunc(res.Timestamp) vv = append(vv, v) }
Additional context Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered:
Makes sense to me. Will PR.
Sorry, something went wrong.
support for sql.Scanner on DateTime should do it.
@bzon addressed by #767
Requires your type to implement sql.Scanner e.g.
type CustomDateTime time.Time func (ct *CustomDateTime) Scan(src any) error { if t, ok := src.(time.Time); ok { *ct = CustomDateTime(t) return nil } return fmt.Errorf("cannot scan %T into CustomDateTime", src) }
gingerwizard
Successfully merging a pull request may close this issue.
Is your feature request related to a problem? Please describe.
I have a struct with a custom time type
CustomDateTime
. I use it overtime.Time
because I change the way how it is stringified in json.However, I get an error with this code:
When the using
sql
driver, I have no problem usingDateTime
column type to a struct field with typeCustomDateTime
.Describe the solution you'd like
I want the same usage when I was using the
sql
driver.I think #720 is a good reference for the solution.
Describe alternatives you've considered
My alternative solution is to create a temporary alias struct and use row scan.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: