Skip to content

Commit

Permalink
Merge pull request #103 from fyyang/master
Browse files Browse the repository at this point in the history
add: mysql add tablePrefix
  • Loading branch information
xxjwxc authored Jan 8, 2021
2 parents a60ccdc + 039050f commit 22d40a2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ is_table_name : false # Whether to out GetTableName/column function
is_null_to_point : false # database is 'DEFAULT NULL' then set element type as point
is_web_tag: false
is_web_tag_pk_hidden: false
table_prefix: "" #table prefix

db_info :
host : "127.0.0.1"
Expand Down
1 change: 1 addition & 0 deletions README_zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ is_table_name: false # 是否直接生成表名,列名
is_null_to_point: false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
is_web_tag: false
is_web_tag_pk_hidden: false
table_prefix: "" #表前缀
db_info:
host : 127.0.0.1
port : 3306
Expand Down
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ is_foreign_key : true # 是否导出外键关联
is_gui : false # 是否ui模式显示
is_table_name : true # 是否直接生成表名,列名
is_null_to_point : false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
table_prefix : "" # 表前缀, 如果有则使用, 没有留空
db_info:
host : 127.0.0.1 # type=1的时候,host为yml文件全路径
port : 3306
Expand Down
6 changes: 6 additions & 0 deletions data/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func init() {
rootCmd.MarkFlagRequired("url tag")

rootCmd.Flags().Int("port", 3306, "端口号")

rootCmd.Flags().StringP("table_prefix", "t", "", "表前缀")
}

// initConfig reads in config file and ENV variables if set.
Expand Down Expand Up @@ -111,4 +113,8 @@ func MergeMysqlDbInfo() {
ig := config.GetIsGUI()
mycobra.IfReplace(rootCmd, "gui", &ig) // 如果设置了,更新
config.SetIsGUI(ig)

tablePrefix := config.GetTablePrefix()
mycobra.IfReplace(rootCmd, "tablePrefix", &tablePrefix) // 如果设置了,更新
config.SetTablePrefix(tablePrefix)
}
11 changes: 11 additions & 0 deletions data/config/MyIni.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
IsGUI bool `yaml:"is_gui"` //
IsTableName bool `yaml:"is_table_name"`
IsNullToPoint bool `yaml:"is_null_to_point"` // null to porint
TablePrefix string `yaml:"table_prefix"` // 表前缀
}

// DBInfo mysql database information. mysql 数据库信息
Expand Down Expand Up @@ -205,3 +206,13 @@ func SetIsNullToPoint(b bool) {
func GetIsNullToPoint() bool {
return _map.IsNullToPoint
}

// SetTablePrefix set table prefix
func SetTablePrefix(t string) {
_map.TablePrefix = t
}

// GetTablePrefix get table prefix
func GetTablePrefix() string {
return _map.TablePrefix
}
1 change: 1 addition & 0 deletions data/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var _map = Config{
IsOutSQL: false,
IsOutFunc: true,
IsGUI: false,
TablePrefix: "",
}

var configPath string
Expand Down
10 changes: 10 additions & 0 deletions data/view/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,19 @@ func (m *_Model) GetPackage() genstruct.GenPackage {
if m.pkg == nil {
var pkg genstruct.GenPackage
pkg.SetPackage(m.info.PackageName) //package name

tablePrefix := config.GetTablePrefix()

for _, tab := range m.info.TabList {
var sct genstruct.GenStruct

sct.SetTableName(tab.Name)

//如果设置了表前缀
if tablePrefix != "" {
tab.Name = strings.TrimLeft(tab.Name, tablePrefix)
}

sct.SetStructName(getCamelName(tab.Name)) // Big hump.大驼峰
sct.SetNotes(tab.Notes)
sct.AddElement(m.genTableElement(tab.Em)...) // build element.构造元素
Expand Down
Binary file modified gormt.exe
Binary file not shown.

0 comments on commit 22d40a2

Please sign in to comment.