fix: the new RawFieldNames considers the tag with options. (#1663)

Co-authored-by: JinfaWang <wangjinfa@iie.ac.cn>
This commit is contained in:
Mervin.Wong
2022-03-20 16:59:19 +08:00
committed by GitHub
parent 5c169f4f49
commit 93d524b797
2 changed files with 35 additions and 3 deletions

View File

@@ -41,10 +41,25 @@ func RawFieldNames(in interface{}, postgresSql ...bool) []string {
out = append(out, fmt.Sprintf("`%s`", fi.Name))
}
default:
if pg {
out = append(out, tagv)
//get tag name with the tag opton, e.g.:
//`db:"id"`
//`db:"id,type=char,length=16"`
//`db:",type=char,length=16"`
if strings.Contains(tagv, ",") {
tagv = strings.TrimSpace(strings.Split(tagv, ",")[0])
}
if tagv != "" {
if pg {
out = append(out, tagv)
} else {
out = append(out, fmt.Sprintf("`%s`", tagv))
}
} else {
out = append(out, fmt.Sprintf("`%s`", tagv))
if pg {
out = append(out, fi.Name)
} else {
out = append(out, fmt.Sprintf("`%s`", fi.Name))
}
}
}
}