From 5d1bfbad59622e966ad6187694141ed11c6d78c2 Mon Sep 17 00:00:00 2001 From: "zhang.tiancheng" Date: Wed, 8 Dec 2021 16:51:13 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20model=E6=98=AF=E5=90=A6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8gorm.Model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yml | 1 + data/config/MyIni.go | 12 +++++++++--- data/config/common.go | 13 +++++++------ data/view/model/genmssql/common.go | 2 +- data/view/model/genmysql/common.go | 2 +- data/view/model/gensqlite/common.go | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/config.yml b/config.yml index cb36edf..fd255b4 100644 --- a/config.yml +++ b/config.yml @@ -5,6 +5,7 @@ url_tag : json # web url tag(json,db(https://github.com/google/go-querystring)) language : # 语言(English,中 文) db_tag : gorm # 数据库标签名(gorm,db) simple : true # 简单输出(默认只输出gorm主键和字段标签) +use_gorm_model : false # model是否使用gorm.Model is_db_tag : true # 是否输出 数据库标签(gorm,db) is_out_sql : false # 是否输出 sql 原信息 is_out_func : true # 是否输出 快捷函数 diff --git a/data/config/MyIni.go b/data/config/MyIni.go index 280fdf9..cc12dc4 100644 --- a/data/config/MyIni.go +++ b/data/config/MyIni.go @@ -12,9 +12,10 @@ type Config struct { CfgBase `yaml:"base"` DBInfo DBInfo `yaml:"db_info"` OutDir string `yaml:"out_dir"` - URLTag string `yaml:"url_tag"` // url tag - Language string `yaml:"language"` // language - DbTag string `yaml:"db_tag"` // 数据库标签(gormt,db) + URLTag string `yaml:"url_tag"` // url tag + Language string `yaml:"language"` // language + DbTag string `yaml:"db_tag"` // 数据库标签(gormt,db) + UserGormModel bool `yaml:"user_gorm_model"` //model是否使用gorm.Model Simple bool `yaml:"simple"` IsWEBTag bool `yaml:"is_web_tag"` IsWebTagPkHidden bool `yaml:"is_web_tag_pk_hidden"` // web标记是否隐藏主键 @@ -209,6 +210,11 @@ func SetDBTag(s string) { _map.DbTag = s } +// GetUserGormModel get `use gorm.Model or not`. +func GetUserGormModel() bool { + return _map.UserGormModel +} + // SetIsNullToPoint if with null to porint in struct func SetIsNullToPoint(b bool) { _map.IsNullToPoint = b diff --git a/data/config/common.go b/data/config/common.go index 065299c..c56c95e 100644 --- a/data/config/common.go +++ b/data/config/common.go @@ -32,12 +32,13 @@ var _map = Config{ Password: "root", Database: "test", }, - OutDir: "./model", - URLTag: "json", - Language: "中 文", - DbTag: "gorm", - Simple: false, - IsWEBTag: false, + OutDir: "./model", + URLTag: "json", + Language: "中 文", + DbTag: "gorm", + UserGormModel: false, + Simple: false, + IsWEBTag: false, // SingularTable: true, IsForeignKey: true, IsOutSQL: false, diff --git a/data/view/model/genmssql/common.go b/data/view/model/genmssql/common.go index cc2148c..8f7d78b 100644 --- a/data/view/model/genmssql/common.go +++ b/data/view/model/genmssql/common.go @@ -11,7 +11,7 @@ import ( // filterModel filter.过滤 gorm.Model func filterModel(list *[]genColumns) bool { - if config.GetDBTag() != "gorm" { + if config.GetDBTag() != "gorm" || !config.GetUserGormModel() { return false } diff --git a/data/view/model/genmysql/common.go b/data/view/model/genmysql/common.go index d36d787..f103395 100644 --- a/data/view/model/genmysql/common.go +++ b/data/view/model/genmysql/common.go @@ -11,7 +11,7 @@ import ( // filterModel filter.过滤 gorm.Model func filterModel(list *[]genColumns) bool { - if config.GetDBTag() != "gorm" { + if config.GetDBTag() != "gorm" || !config.GetUserGormModel() { return false } diff --git a/data/view/model/gensqlite/common.go b/data/view/model/gensqlite/common.go index efbb7d3..7c6f962 100644 --- a/data/view/model/gensqlite/common.go +++ b/data/view/model/gensqlite/common.go @@ -10,7 +10,7 @@ import ( // filterModel filter.过滤 gorm.Model func filterModel(list *[]genColumns) bool { - if config.GetDBTag() != "gorm" { + if config.GetDBTag() != "gorm" || !config.GetUserGormModel() { return false }