Skip to content

Commit

Permalink
[AB#1669514] alternate approach; more generalized
Browse files Browse the repository at this point in the history
  • Loading branch information
ChronosMasterOfAllTime committed Sep 20, 2024
1 parent 6d42602 commit d4c0161
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,14 @@ func arrayToString(v driver.Value, tsmode snowflakeType, params map[string]*stri
} else if reflect.ValueOf(v).Len() == 0 {
value := "[]"
return bindingValue{&value, "json", nil}, nil
} else if v1.Kind() == reflect.Array && v1.Type().Elem().Kind() == reflect.Uint8 && v1.Len() == 16 { // special case for all UUID
} else if hasStringMethod(v1) { // alternate approach; check for stringer method
method := v1.MethodByName("String")
result := method.Call(nil) // Call with no arguments
if len(result) == 1 && result[0].Kind() == reflect.String {
value := result[0].String()
return bindingValue{&value, "", nil}, nil
}
} else if v1.Type().Elem().Kind() == reflect.Uint8 && v1.Len() == 16 { // special case for all UUID; which do we like better?
// Convert the value to [16]byte
var bytes UUID
for idx := 0; idx < 16; idx++ {
Expand Down Expand Up @@ -750,6 +757,11 @@ func isArrayOfStructs(v any) bool {
return reflect.TypeOf(v).Elem().Kind() == reflect.Struct || (reflect.TypeOf(v).Elem().Kind() == reflect.Pointer && reflect.TypeOf(v).Elem().Elem().Kind() == reflect.Struct)
}

func hasStringMethod(v reflect.Value) bool {
method := v.MethodByName("String")
return method.IsValid()
}

func structValueToString(v driver.Value, tsmode snowflakeType, params map[string]*string) (bindingValue, error) {
switch typedVal := v.(type) {
case time.Time:
Expand Down

0 comments on commit d4c0161

Please sign in to comment.