From 849483b613bb79de377a7234651fbdaaf9073387 Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 25 Dec 2024 20:22:03 +0800 Subject: [PATCH] feat: gen model --- cmd/gen_model.go | 15 ++++----------- templates/project/database/transform.yaml.tpl | 3 ++- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/cmd/gen_model.go b/cmd/gen_model.go index cbe03bb..219e1cd 100644 --- a/cmd/gen_model.go +++ b/cmd/gen_model.go @@ -93,21 +93,14 @@ func commandGenModelE(cmd *cobra.Command, args []string) error { return defaultTableModelField } - splits := strings.SplitN(toType, ".", 2) - typeName := splits[len(splits)-1] - - pkg := splits[0] - if strings.HasPrefix(pkg, "~") { - pkg = strings.Replace(pkg, "~", gomod.GetModuleName(), 1) + if strings.Contains(toType, "[") && strings.HasSuffix(toType, "]") { + toType = strings.Replace(toType, "[", "[fields.", 1) } - pkgSplits := strings.Split(splits[0], "/") - typePkg := pkgSplits[len(pkgSplits)-1] - defaultTableModelField = defaultTableModelField. UseType(template.Type{ - Name: fmt.Sprintf("%s.%s", typePkg, typeName), - ImportPath: pkg, + Name: fmt.Sprintf("fields.%s", toType), + ImportPath: fmt.Sprintf("%s/database/fields", gomod.GetModuleName()), }) log.Infof("Convert table %s field %s type to : %s", table.Name, column.Name, toType) diff --git a/templates/project/database/transform.yaml.tpl b/templates/project/database/transform.yaml.tpl index aeca555..d5d944d 100755 --- a/templates/project/database/transform.yaml.tpl +++ b/templates/project/database/transform.yaml.tpl @@ -1,4 +1,5 @@ # ignores: [] # ignore tables # types: # users: # table name -# meta: ~/database/fields.UserMeta +# meta: UserMeta +# meta: Json[UserMeta]