Closed schalekamp closed 1 month ago
Hey mate,
I tried to create a test case for your issue here: 1409_test.go. After reviewing the codebase, I noticed something in the Append method for the Date type:
func (col *Date) Append(v any) (nulls []uint8, err error) {
switch v := v.(type) {
case []time.Time:
for _, t := range v {
col.col.Append(t)
}
case []*time.Time:
nulls = make([]uint8, len(v))
for i, v := range v {
switch {
case v != nil:
col.col.Append(*v)
default:
nulls[i] = 1
col.col.Append(time.Time{})
}
}
case []sql.NullTime:
nulls = make([]uint8, len(v))
for i := range v {
col.AppendRow(v[i])
}
case []*sql.NullTime:
nulls = make([]uint8, len(v))
for i := range v {
if v[i] == nil {
nulls[i] = 1
}
col.AppendRow(v[i])
}
case []string:
nulls = make([]uint8, len(v))
for i := range v {
value, err := col.parseDate(v[i])
if err != nil {
return nil, err
}
col.col.Append(value)
}
case []*string:
nulls = make([]uint8, len(v))
for i := range v {
if v[i] == nil || *v[i] == "" {
nulls[i] = 1
col.col.Append(time.Time{})
} else {
value, err := col.parseDate(*v[i])
if err != nil {
return nil, err
}
col.col.Append(value)
}
}
default:
if valuer, ok := v.(driver.Valuer); ok {
val, err := valuer.Value()
if err != nil {
return nil, &ColumnConverterError{
Op: "Append",
To: "Date",
From: fmt.Sprintf("%T", v),
Hint: "could not get driver.Valuer value",
}
}
return col.Append(val)
}
return nil, &ColumnConverterError{
Op: "Append",
To: "Date",
From: fmt.Sprintf("%T", v),
}
}
return
}
It seems that the Append method expects a slice data type to work correctly. When I used a slice in the test case, it functioned as intended.
You are correct. In my naive understanding I did not expect this method to only take a slice. User error. :)
Observed
batch.Append works for the Date type, but batch.Column(n).Append does NOT work for the Date type
Expected behaviour
I would expect this to work for both
Code example
Error log