Feature model fix (#362)

* fix sql builderx adding raw string quotation marks incompatibility bug

* add unit test

* remove comments

* fix sql builderx adding raw string quotation marks incompatibility bug
This commit is contained in:
anqiansong
2021-01-08 12:01:21 +08:00
committed by GitHub
parent 57b73d8b49
commit 6c624a6ed0
7 changed files with 72 additions and 26 deletions

View File

@@ -46,6 +46,7 @@ func ToMap(in interface{}) map[string]interface{} {
return out
}
// deprecated: use RawFieldNames instead automaticly while model generating after goctl version v1.1.0
func FieldNames(in interface{}) []string {
out := make([]string, 0)
v := reflect.ValueOf(in)
@@ -61,9 +62,32 @@ func FieldNames(in interface{}) []string {
// gets us a StructField
fi := typ.Field(i)
if tagv := fi.Tag.Get(dbTag); tagv != "" {
out = append(out, fmt.Sprintf("`%v`", tagv))
out = append(out, tagv)
} else {
out = append(out, fmt.Sprintf("`%v`", fi.Name))
out = append(out, fi.Name)
}
}
return out
}
func RawFieldNames(in interface{}) []string {
out := make([]string, 0)
v := reflect.ValueOf(in)
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
// we only accept structs
if v.Kind() != reflect.Struct {
panic(fmt.Errorf("ToMap only accepts structs; got %T", v))
}
typ := v.Type()
for i := 0; i < v.NumField(); i++ {
// gets us a StructField
fi := typ.Field(i)
if tagv := fi.Tag.Get(dbTag); tagv != "" {
out = append(out, fmt.Sprintf("`%s`", tagv))
} else {
out = append(out, fmt.Sprintf(`"%s"`, fi.Name))
}
}
return out