You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package gen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/model/sql/parser"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/model/sql/template"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util/templatex"
|
|
|
|
)
|
|
|
|
|
|
|
|
func genFields(fields []parser.Field) (string, error) {
|
|
|
|
var list []string
|
|
|
|
for _, field := range fields {
|
|
|
|
result, err := genField(field)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
list = append(list, result)
|
|
|
|
}
|
|
|
|
return strings.Join(list, "\n"), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func genField(field parser.Field) (string, error) {
|
|
|
|
tag, err := genTag(field.Name.Source())
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
output, err := templatex.With("types").
|
|
|
|
Parse(template.Field).
|
|
|
|
Execute(map[string]interface{}{
|
|
|
|
"name": field.Name.ToCamel(),
|
|
|
|
"type": field.DataType,
|
|
|
|
"tag": tag,
|
|
|
|
"hasComment": field.Comment != "",
|
|
|
|
"comment": field.Comment,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return output.String(), nil
|
|
|
|
}
|