From 808b4e496afe62d14a83a2e592bf7e0f59dcb5af Mon Sep 17 00:00:00 2001 From: hoshi <63923637+hoshi200@users.noreply.github.com> Date: Fri, 2 May 2025 16:10:47 +0800 Subject: [PATCH] feat:add cache prefix support to pg (#4741) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 郑好 --- tools/goctl/internal/flags/default_en.json | 1 + tools/goctl/model/cmd.go | 1 + tools/goctl/model/sql/command/command.go | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/goctl/internal/flags/default_en.json b/tools/goctl/internal/flags/default_en.json index ad51100c5..d33bb3eec 100644 --- a/tools/goctl/internal/flags/default_en.json +++ b/tools/goctl/internal/flags/default_en.json @@ -185,6 +185,7 @@ }, "pg": { "short": "Generate postgresql model", + "prefix": "The cache prefix, effective when --cache is true", "datasource": { "short": "Generate model from datasource", "url": "The data source of database,like \"postgres://root:password@127.0.0.1:5432/database?sslmode=disable\"", diff --git a/tools/goctl/model/cmd.go b/tools/goctl/model/cmd.go index 7ae7477fd..50619d76c 100644 --- a/tools/goctl/model/cmd.go +++ b/tools/goctl/model/cmd.go @@ -58,6 +58,7 @@ func init() { pgDatasourceCmdFlags.StringVar(&command.VarStringBranch, "branch") pgCmd.PersistentFlags().StringSliceVarPWithDefaultValue(&command.VarStringSliceIgnoreColumns, "ignore-columns", "i", []string{"create_at", "created_at", "create_time", "update_at", "updated_at", "update_time"}) + pgCmd.PersistentFlags().StringVarPWithDefaultValue(&command.VarStringCachePrefix, "prefix", "p", "cache") mongoCmdFlags.StringSliceVarP(&mongo.VarStringSliceType, "type", "t") mongoCmdFlags.BoolVarP(&mongo.VarBoolCache, "cache", "c") diff --git a/tools/goctl/model/sql/command/command.go b/tools/goctl/model/sql/command/command.go index 8fbcb5cd2..896c6a0c7 100644 --- a/tools/goctl/model/sql/command/command.go +++ b/tools/goctl/model/sql/command/command.go @@ -204,6 +204,7 @@ func PostgreSqlDataSource(_ *cobra.Command, _ []string) error { home := VarStringHome remote := VarStringRemote branch := VarStringBranch + prefix := VarStringCachePrefix if len(remote) > 0 { repo, _ := file.CloneIntoGitHome(remote, branch) if len(repo) > 0 { @@ -225,7 +226,7 @@ func PostgreSqlDataSource(_ *cobra.Command, _ []string) error { } ignoreColumns := mergeColumns(VarStringSliceIgnoreColumns) - return fromPostgreSqlDataSource(url, patterns, dir, schema, cfg, cache, idea, VarBoolStrict, ignoreColumns) + return fromPostgreSqlDataSource(url, patterns, dir, schema, prefix, cfg, cache, idea, VarBoolStrict, ignoreColumns) } type ddlArg struct { @@ -339,7 +340,7 @@ func fromMysqlDataSource(arg dataSourceArg) error { return generator.StartFromInformationSchema(matchTables, arg.cache, arg.strict) } -func fromPostgreSqlDataSource(url string, pattern pattern, dir, schema string, cfg *config.Config, cache, idea, strict bool, ignoreColumns []string) error { +func fromPostgreSqlDataSource(url string, pattern pattern, dir, schema string, prefix string, cfg *config.Config, cache, idea, strict bool, ignoreColumns []string) error { log := console.NewConsole(idea) if len(url) == 0 { log.Error("%v", "expected data source of postgresql, but nothing found") @@ -381,7 +382,7 @@ func fromPostgreSqlDataSource(url string, pattern pattern, dir, schema string, c return errors.New("no tables matched") } - generator, err := gen.NewDefaultGenerator("", dir, cfg, gen.WithConsoleOption(log), gen.WithPostgreSql(), gen.WithIgnoreColumns(ignoreColumns)) + generator, err := gen.NewDefaultGenerator(prefix, dir, cfg, gen.WithConsoleOption(log), gen.WithPostgreSql(), gen.WithIgnoreColumns(ignoreColumns)) if err != nil { return err }