refactor with improved developer ux in mind

- Most functions now live directly in the dbx package
- dbxp and dbxm are now ONLY the few functions that cannot be shared
This commit is contained in:
Elijah Duffy
2025-06-12 17:44:44 -07:00
parent 18e669101e
commit 32567471e1
7 changed files with 332 additions and 357 deletions

View File

@@ -0,0 +1,36 @@
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.Ptr {
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
}