I'm using Gorm, and I have an enum backed by a int32. I'm trying to store it to a Nullable(Int32) by using a pointer to the enum value. When trying to store the row, I get the error attached below.
I tried implementing driver.Valuer, and it didn't help.
From debugging a bit I notice that clickhouse-go uses the valuer to determine the nil-or-not-nil state, but not the actual value of the field.
Expected behaviour
The library should either automatically handle the conversion between the enum and the backing type, or at the very least it should use the driver.Valuer implementation properly to determine the value.
Code example
type MyEnum int32
// ...
func (m *MyEum) Value() (driver.Value, error) {
converter := driver.Null{Converter: driver.Int32}
if m == nil {
return converter.ConvertValue(nil)
}
return converter.ConvertValue(int32(*m))
}
type MyEntity struct {
Timestamp time.Time `gorm:"type:DateTime('UTC')"`
MyEnumValue *MyEnum `gorm:"type:Nullable(Int32)"`
// ...
}
Error log
clickhouse [AppendRow]: MyEnumValue clickhouse [AppendRow]: converting *example.MyEnum to Int32 is unsupported
To support for type alias, having driver.Valuer interface support is best. It already exists for string, but not numeric types. I will have look on this.
Describe the bug
I'm using Gorm, and I have an enum backed by a
int32
. I'm trying to store it to aNullable(Int32)
by using a pointer to the enum value. When trying to store the row, I get the error attached below. I tried implementingdriver.Valuer
, and it didn't help.From debugging a bit I notice that
clickhouse-go
uses the valuer to determine the nil-or-not-nil state, but not the actual value of the field.Expected behaviour
The library should either automatically handle the conversion between the enum and the backing type, or at the very least it should use the
driver.Valuer
implementation properly to determine the value.Code example
Error log
clickhouse [AppendRow]: MyEnumValue clickhouse [AppendRow]: converting *example.MyEnum to Int32 is unsupported
Configuration
Environment
github.com/ClickHouse/clickhouse-go/v2 v2.8.2
go version go1.20.4 linux/amd64
Linux d30d8d32178c 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 GNU/Linux
ClickHouse server
22.3.12.21.altinitystable
CREATE TABLE
statements for tables involved: