feat: let model customizable (#1738)
parent
7e0b0ab0b1
commit
6dccfa29fd
@ -0,0 +1,26 @@
|
||||
package gen
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/model/sql/template"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
func genTableName(table Table) (string, error) {
|
||||
text, err := pathx.LoadTemplate(category, tableNameTemplateFile, template.TableName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
output, err := util.With("tableName").
|
||||
Parse(text).
|
||||
Execute(map[string]interface{}{
|
||||
"tableName": table.Name.Source(),
|
||||
"upperStartCamelObject": table.Name.ToCamel(),
|
||||
})
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
return output.String(), nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package template
|
||||
|
||||
// Field defines a filed template for types
|
||||
var Field = `{{.name}} {{.type}} {{.tag}} {{if .hasComment}}// {{.comment}}{{end}}`
|
||||
const Field = `{{.name}} {{.type}} {{.tag}} {{if .hasComment}}// {{.comment}}{{end}}`
|
||||
|
@ -0,0 +1,8 @@
|
||||
package template
|
||||
|
||||
// TableName defines a template that generate the tableName method.
|
||||
const TableName = `
|
||||
func (m *default{{.upperStartCamelObject}}Model) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
`
|
@ -1,4 +1,4 @@
|
||||
package template
|
||||
|
||||
// Tag defines a tag template text
|
||||
var Tag = "`db:\"{{.field}}\"`"
|
||||
const Tag = "`db:\"{{.field}}\"`"
|
||||
|
Loading…
Reference in New Issue