diff --git a/README.md b/README.md index 2abc09b..0b49998 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,11 @@ Using `Dictionary` as an example, the configuration file is as follows `dictiona disable_pagination: true fill_gorm_commit: true fill_router_prefix: true + rewrite: + schema: true + dal: true + biz: true + api: true tpl_type: "tree" fields: - name: Code diff --git a/internal/actions/generate.go b/internal/actions/generate.go index 33b9af4..fc9bc7d 100644 --- a/internal/actions/generate.go +++ b/internal/actions/generate.go @@ -246,7 +246,27 @@ func (a *GenerateAction) generate(ctx context.Context, dataItem *schema.S) error return err } - err = a.write(ctx, dataItem.Module, dataItem.Name, parser.StructPackageTplPaths[pkgName], tplData, !dataItem.ForceWrite) + var rewrite bool + switch pkgName { + case "schema": + if dataItem.Rewrite != nil && dataItem.Rewrite.Schema { + rewrite = true + } + case "dal": + if dataItem.Rewrite != nil && dataItem.Rewrite.Dal { + rewrite = true + } + case "biz": + if dataItem.Rewrite != nil && dataItem.Rewrite.Biz { + rewrite = true + } + case "api": + if dataItem.Rewrite != nil && dataItem.Rewrite.Api { + rewrite = true + } + } + + err = a.write(ctx, dataItem.Module, dataItem.Name, parser.StructPackageTplPaths[pkgName], tplData, !rewrite) if err != nil { return err } diff --git a/internal/schema/struct.go b/internal/schema/struct.go index abee4ea..cde774f 100644 --- a/internal/schema/struct.go +++ b/internal/schema/struct.go @@ -23,7 +23,7 @@ type S struct { TableName string `yaml:"table_name,omitempty" json:"table_name,omitempty"` Comment string `yaml:"comment,omitempty" json:"comment,omitempty"` Outputs []string `yaml:"outputs,omitempty" json:"outputs,omitempty"` - ForceWrite bool `yaml:"force_write,omitempty" json:"force_write,omitempty"` + Rewrite *Rewrite `yaml:"rewrite,omitempty" json:"force_write,omitempty"` TplType string `yaml:"tpl_type,omitempty" json:"tpl_type,omitempty"` // crud/tree DisablePagination bool `yaml:"disable_pagination,omitempty" json:"disable_pagination,omitempty"` DisableDefaultFields bool `yaml:"disable_default_fields,omitempty" json:"disable_default_fields,omitempty"` @@ -120,6 +120,13 @@ func (a *S) Format() *S { return a } +type Rewrite struct { + Schema bool `yaml:"schema,omitempty" json:"schema,omitempty"` + Dal bool `yaml:"dal,omitempty" json:"dal,omitempty"` + Biz bool `yaml:"biz,omitempty" json:"biz,omitempty"` + Api bool `yaml:"api,omitempty" json:"api,omitempty"` +} + type Field struct { Name string `yaml:"name,omitempty" json:"name,omitempty"` Type string `yaml:"type,omitempty" json:"type,omitempty"`