Files
dbx/internal/dbxshared/dbxshared.go
Elijah Duffy 6ab100cc46 upgrade to go 1.25 & port helpers
Removed ExprID and ExprEnum in favour of generics.
2026-01-28 11:22:06 -08:00

37 lines
851 B
Go

package dbxshared
import (
"reflect"
"strings"
)
// DestName returns the name of the type passed as `destTypeStruct` as a string,
// normalized for compatibility with the Jet QRM.
func DestName(destTypeStruct any, path ...string) string {
v := reflect.ValueOf(destTypeStruct)
for v.Kind() == reflect.Pointer {
v = v.Elem()
}
destIdent := v.Type().String()
destIdent = destIdent[strings.LastIndex(destIdent, ".")+1:]
for i, p := range path {
if v.Kind() != reflect.Struct {
DBModule.Logger().Error("DestName: path parent is not a struct", "path", destIdent+"."+strings.Join(path[:i+1], "."))
return ""
}
v = v.FieldByName(p)
if !v.IsValid() {
DBModule.Logger().Error("DestName: field does not exist", "path", destIdent+"."+strings.Join(path[:i+1], "."))
return ""
}
destIdent += "." + p
}
return destIdent
}