feat: gen model

This commit is contained in:
Rogee
2024-12-25 20:22:03 +08:00
parent 7dde1820c3
commit 849483b613
2 changed files with 6 additions and 12 deletions

View File

@@ -93,21 +93,14 @@ func commandGenModelE(cmd *cobra.Command, args []string) error {
return defaultTableModelField return defaultTableModelField
} }
splits := strings.SplitN(toType, ".", 2) if strings.Contains(toType, "[") && strings.HasSuffix(toType, "]") {
typeName := splits[len(splits)-1] toType = strings.Replace(toType, "[", "[fields.", 1)
pkg := splits[0]
if strings.HasPrefix(pkg, "~") {
pkg = strings.Replace(pkg, "~", gomod.GetModuleName(), 1)
} }
pkgSplits := strings.Split(splits[0], "/")
typePkg := pkgSplits[len(pkgSplits)-1]
defaultTableModelField = defaultTableModelField. defaultTableModelField = defaultTableModelField.
UseType(template.Type{ UseType(template.Type{
Name: fmt.Sprintf("%s.%s", typePkg, typeName), Name: fmt.Sprintf("fields.%s", toType),
ImportPath: pkg, ImportPath: fmt.Sprintf("%s/database/fields", gomod.GetModuleName()),
}) })
log.Infof("Convert table %s field %s type to : %s", table.Name, column.Name, toType) log.Infof("Convert table %s field %s type to : %s", table.Name, column.Name, toType)

View File

@@ -1,4 +1,5 @@
# ignores: [] # ignore tables # ignores: [] # ignore tables
# types: # types:
# users: # table name # users: # table name
# meta: ~/database/fields.UserMeta # meta: UserMeta
# meta: Json[UserMeta]