split mysql specific code into separate package

This commit is contained in:
Elijah Duffy
2025-06-04 18:17:39 -07:00
parent 757483a574
commit d773164227
3 changed files with 77 additions and 64 deletions

38
generic/generic.go Normal file
View File

@@ -0,0 +1,38 @@
package dbxgeneric
import (
"reflect"
"strings"
"gitea.auvem.com/go-toolkit/app"
)
// DestName returns the name of the type passed as `destTypeStruct` as a string,
// normalized for compatibility with the Jet QRM.
func DestName(mod *app.Module, 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 {
mod.Logger().Error("DestName: path parent is not a struct", "path", destIdent+"."+strings.Join(path[:i+1], "."))
return ""
}
v = v.FieldByName(p)
if !v.IsValid() {
mod.Logger().Error("DestName: field does not exist", "path", destIdent+"."+strings.Join(path[:i+1], "."))
return ""
}
destIdent += "." + p
}
return destIdent
}