@@ -16,8 +16,9 @@ is_gui : false # 是否ui模式显示
|
|||||||
is_table_name : true # 是否直接生成表名
|
is_table_name : true # 是否直接生成表名
|
||||||
is_column_name : true # 是否直接生成列名
|
is_column_name : true # 是否直接生成列名
|
||||||
is_null_to_point : false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
|
is_null_to_point : false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
|
||||||
table_prefix : "" # 表前缀, 如果有则使用, 没有留空
|
table_prefix : "" # 表前缀, 如果有则使用, 没有留空(如果表前缀以"-"开头,则表示去掉该前缀,struct、文件名都会去掉该前缀)
|
||||||
table_names: "" # 指定表生成,多个表用,隔开
|
table_names: "" # 指定表生成,多个表用,隔开
|
||||||
|
is_out_file_by_table_name: false # 是否根据表名生成多个model
|
||||||
|
|
||||||
db_info:
|
db_info:
|
||||||
host : 127.0.0.1 # type=1的时候,host为yml文件全路径
|
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 { //
|
func GetTablePrefixName(name string) string { //
|
||||||
tablePrefix := config.GetTablePrefix()
|
tablePrefix := config.GetTablePrefix()
|
||||||
//如果设置了表前缀
|
//如果设置了表前缀
|
||||||
if tablePrefix != "" {
|
if tablePrefix == "" || strings.HasPrefix(tablePrefix, "-") {
|
||||||
name = tablePrefix + name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
return name
|
return tablePrefix + name
|
||||||
}
|
}
|
||||||
|
|
||||||
func FilterKeywords(src string) string {
|
func FilterKeywords(src string) string {
|
||||||
|
|||||||
@@ -51,24 +51,36 @@ func Generate(info DBInfo) (out []GenOutInfo, m _Model) {
|
|||||||
return
|
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
|
// GetPackage gen struct on table
|
||||||
func (m *_Model) GetPackage() genstruct.GenPackage {
|
func (m *_Model) GetPackage() genstruct.GenPackage {
|
||||||
if m.pkg == nil {
|
if m.pkg == nil {
|
||||||
var pkg genstruct.GenPackage
|
var pkg genstruct.GenPackage
|
||||||
pkg.SetPackage(m.info.PackageName) //package name
|
pkg.SetPackage(m.info.PackageName) //package name
|
||||||
|
|
||||||
tablePrefix := config.GetTablePrefix()
|
|
||||||
|
|
||||||
for _, tab := range m.info.TabList {
|
for _, tab := range m.info.TabList {
|
||||||
var sct genstruct.GenStruct
|
var sct genstruct.GenStruct
|
||||||
|
|
||||||
sct.SetTableName(tablePrefix + tab.Name)
|
sct.SetTableName(tab.Name)
|
||||||
|
|
||||||
//如果设置了表前缀
|
|
||||||
// if tablePrefix != "" {
|
|
||||||
// tab.Name = strings.TrimLeft(tab.Name, tablePrefix)
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
tab.Name = getTableNameWithPrefix(tab.Name)
|
||||||
|
fmt.Println(tab.Name)
|
||||||
sct.SetStructName(getCamelName(tab.Name)) // Big hump.大驼峰
|
sct.SetStructName(getCamelName(tab.Name)) // Big hump.大驼峰
|
||||||
sct.SetNotes(tab.Notes)
|
sct.SetNotes(tab.Notes)
|
||||||
sct.AddElement(m.genTableElement(tab.Em)...) // build element.构造元素
|
sct.AddElement(m.genTableElement(tab.Em)...) // build element.构造元素
|
||||||
@@ -88,11 +100,12 @@ func (m *_Model) GenerateByTableName() (out []GenOutInfo) {
|
|||||||
var pkg genstruct.GenPackage
|
var pkg genstruct.GenPackage
|
||||||
pkg.SetPackage(m.info.PackageName) //package name
|
pkg.SetPackage(m.info.PackageName) //package name
|
||||||
var sct genstruct.GenStruct
|
var sct genstruct.GenStruct
|
||||||
|
sct.SetTableName(tab.Name)
|
||||||
|
tab.Name = getTableNameWithPrefix(tab.Name)
|
||||||
sct.SetStructName(getCamelName(tab.Name)) // Big hump.大驼峰
|
sct.SetStructName(getCamelName(tab.Name)) // Big hump.大驼峰
|
||||||
sct.SetNotes(tab.Notes)
|
sct.SetNotes(tab.Notes)
|
||||||
sct.AddElement(m.genTableElement(tab.Em)...) // build element.构造元素
|
sct.AddElement(m.genTableElement(tab.Em)...) // build element.构造元素
|
||||||
sct.SetCreatTableStr(tab.SQLBuildStr)
|
sct.SetCreatTableStr(tab.SQLBuildStr)
|
||||||
sct.SetTableName(tab.Name)
|
|
||||||
pkg.AddStruct(sct)
|
pkg.AddStruct(sct)
|
||||||
var stt GenOutInfo
|
var stt GenOutInfo
|
||||||
stt.FileCtx = pkg.Generate()
|
stt.FileCtx = pkg.Generate()
|
||||||
@@ -320,11 +333,8 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
|
|||||||
// wxw 2021.2.26 17:17
|
// wxw 2021.2.26 17:17
|
||||||
var data funDef
|
var data funDef
|
||||||
data.TableName = tab.Name
|
data.TableName = tab.Name
|
||||||
// tablePrefix := config.GetTablePrefix()
|
tab.Name = getTableNameWithPrefix(tab.Name)
|
||||||
// //如果设置了表前缀
|
|
||||||
// if tablePrefix != "" {
|
|
||||||
// tab.Name = strings.TrimLeft(tab.Name, tablePrefix)
|
|
||||||
// }
|
|
||||||
data.StructName = getCamelName(tab.Name)
|
data.StructName = getCamelName(tab.Name)
|
||||||
|
|
||||||
var primary, unique, uniqueIndex, index []FList
|
var primary, unique, uniqueIndex, index []FList
|
||||||
|
|||||||
Reference in New Issue
Block a user