63187ee905
Export CurrentDialect(), return setup errors when debug logger is not registered, and guard DestName logging when the module is uninitialized. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1012 B
Go
46 lines
1012 B
Go
package dbx
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
|
|
"gitea.auvem.com/go-toolkit/dbx/internal/dbxshared"
|
|
)
|
|
|
|
// 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 {
|
|
destNameLogError("DestName: path parent is not a struct", destIdent+"."+strings.Join(path[:i+1], "."))
|
|
return ""
|
|
}
|
|
|
|
v = v.FieldByName(p)
|
|
|
|
if !v.IsValid() {
|
|
destNameLogError("DestName: field does not exist", destIdent+"."+strings.Join(path[:i+1], "."))
|
|
return ""
|
|
}
|
|
|
|
destIdent += "." + p
|
|
}
|
|
|
|
return destIdent
|
|
}
|
|
|
|
func destNameLogError(msg, path string) {
|
|
if dbxshared.DBModule == nil {
|
|
return
|
|
}
|
|
dbxshared.DBModule.Logger().Error(msg, "path", path)
|
|
}
|