升级生成dao的工具
This commit is contained in:
@ -18,7 +18,7 @@ import (
|
||||
|
||||
const (
|
||||
// CreateSQLColumnTPL 每个字段的模版
|
||||
CreateSQLColumnTPL = "{FIELD} {TYPE} `json:\"{JSON_TAG}\" gorm:\"column:{COLUMN};default:{DEFAULT_VALUE};{NOT_NULL}\"` // {COMMENT}"
|
||||
CreateSQLColumnTPL = " {FIELD} {TYPE} `json:\"{JSON_TAG}\" gorm:\"column:{COLUMN};default:{DEFAULT_VALUE};{NOT_NULL}\"` // {COMMENT}"
|
||||
)
|
||||
|
||||
// BasicTableInfo ...
|
||||
@ -38,7 +38,7 @@ type BasicTableInfo struct {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 4:49 下午 2021/10/25
|
||||
func ParseCreateTableSql(sql string) (string, *BasicTableInfo, error) {
|
||||
func ParseCreateTableSql(sql string, withGetTableFunc bool) (string, *BasicTableInfo, error) {
|
||||
var (
|
||||
stmt sqlparser.Statement
|
||||
err error
|
||||
@ -94,5 +94,25 @@ func ParseCreateTableSql(sql string) (string, *BasicTableInfo, error) {
|
||||
structResult += val + "\n"
|
||||
}
|
||||
structResult = structResult + "}"
|
||||
if withGetTableFunc {
|
||||
// 生成表名称获取方法
|
||||
tableFirst := string([]byte(basic.TableName)[:1])
|
||||
funcTpl := `
|
||||
|
||||
// TableName 获取表名称
|
||||
func ({{TABLE_FIRST}} {{TABLE_STRUCT_NAME}}) TableName() string {
|
||||
return "{{TABLE_NAME}}"
|
||||
}`
|
||||
replaceTable := map[string]string{
|
||||
"{{TABLE_FIRST}}": tableFirst,
|
||||
"{{TABLE_STRUCT_NAME}}": basic.ModelStruct,
|
||||
"{{TABLE_NAME}}": basic.TableName,
|
||||
}
|
||||
for k, v := range replaceTable {
|
||||
funcTpl = strings.ReplaceAll(funcTpl, k, v)
|
||||
}
|
||||
structResult = structResult + funcTpl
|
||||
}
|
||||
|
||||
return structResult, basic, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user