Merge pull request #183 from DowneyL/fix-136

fix:136
master
xxj 3 years ago committed by GitHub
commit a1743973d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,8 +16,9 @@ is_gui : false # 是否ui模式显示
is_table_name : true # 是否直接生成表名
is_column_name : true # 是否直接生成列名
is_null_to_point : false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
table_prefix : "" # 表前缀, 如果有则使用, 没有留空
table_prefix : "" # 表前缀, 如果有则使用, 没有留空(如果表前缀以"-"开头则表示去掉该前缀struct、文件名都会去掉该前缀)
table_names: "" # 指定表生成,多个表用,隔开
is_out_file_by_table_name: false # 是否根据表名生成多个model
db_info:
host : 127.0.0.1 # type=1的时候host为yml文件全路径

@ -51,11 +51,11 @@ func CapLowercase(name string) string { // IDAPIID == > idAPIID
func GetTablePrefixName(name string) string { //
tablePrefix := config.GetTablePrefix()
//如果设置了表前缀
if tablePrefix != "" {
name = tablePrefix + name
if tablePrefix == "" || strings.HasPrefix(tablePrefix, "-") {
return name
}
return name
return tablePrefix + name
}
func FilterKeywords(src string) string {

@ -51,24 +51,36 @@ func Generate(info DBInfo) (out []GenOutInfo, m _Model) {
return
}
// getTableNameWithPrefix get table name with prefix
func getTableNameWithPrefix(tableName string) string {
tablePrefix := config.GetTablePrefix()
if tablePrefix == "" {
return tableName
}
if strings.HasPrefix(tablePrefix, "-") {
trimPrefix := strings.TrimPrefix(tablePrefix, "-")
tableName = strings.TrimPrefix(tableName, trimPrefix)
} else {
tableName = tablePrefix + tableName
}
return tableName
}
// GetPackage gen struct on table
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(tablePrefix + tab.Name)
//如果设置了表前缀
// if tablePrefix != "" {
// tab.Name = strings.TrimLeft(tab.Name, tablePrefix)
// }
sct.SetTableName(tab.Name)
tab.Name = getTableNameWithPrefix(tab.Name)
fmt.Println(tab.Name)
sct.SetStructName(getCamelName(tab.Name)) // Big hump.大驼峰
sct.SetNotes(tab.Notes)
sct.AddElement(m.genTableElement(tab.Em)...) // build element.构造元素
@ -88,11 +100,12 @@ func (m *_Model) GenerateByTableName() (out []GenOutInfo) {
var pkg genstruct.GenPackage
pkg.SetPackage(m.info.PackageName) //package name
var sct genstruct.GenStruct
sct.SetTableName(tab.Name)
tab.Name = getTableNameWithPrefix(tab.Name)
sct.SetStructName(getCamelName(tab.Name)) // Big hump.大驼峰
sct.SetNotes(tab.Notes)
sct.AddElement(m.genTableElement(tab.Em)...) // build element.构造元素
sct.SetCreatTableStr(tab.SQLBuildStr)
sct.SetTableName(tab.Name)
pkg.AddStruct(sct)
var stt GenOutInfo
stt.FileCtx = pkg.Generate()
@ -320,11 +333,8 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
// wxw 2021.2.26 17:17
var data funDef
data.TableName = tab.Name
// tablePrefix := config.GetTablePrefix()
// //如果设置了表前缀
// if tablePrefix != "" {
// tab.Name = strings.TrimLeft(tab.Name, tablePrefix)
// }
tab.Name = getTableNameWithPrefix(tab.Name)
data.StructName = getCamelName(tab.Name)
var primary, unique, uniqueIndex, index []FList

Loading…
Cancel
Save