add: now, you can set tablePrefix
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 数据库信息
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ var _map = Config{
|
||||
IsOutSQL: false,
|
||||
IsOutFunc: true,
|
||||
IsGUI: false,
|
||||
TablePrefix: "",
|
||||
}
|
||||
|
||||
var configPath string
|
||||
|
||||
@@ -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.构造元素
|
||||
|
||||
Reference in New Issue
Block a user