Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug: crash when generate model with goctl. #1777

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tools/goctl/model/sql/gen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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"
"github.com/zeromicro/go-zero/tools/goctl/util/stringx"
)

func genFields(table Table, fields []*parser.Field) (string, error) {
Expand Down Expand Up @@ -38,7 +39,7 @@ func genField(table Table, field *parser.Field) (string, error) {
output, err := util.With("types").
Parse(text).
Execute(map[string]interface{}{
"name": field.Name.ToCamel(),
"name": stringx.From(field.Name.ReplaceAll("-", "_")).ToCamel(),
600ML marked this conversation as resolved.
Show resolved Hide resolved
"type": field.DataType,
"tag": tag,
"hasComment": field.Comment != "",
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/model/sql/gen/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func genInsert(table Table, withCache, postgreSql bool) (string, string, error)
expressionValues := make([]string, 0)
var count int
for _, field := range table.Fields {
camel := field.Name.ToCamel()
camel := stringx.From(field.Name.ReplaceAll("-", "_")).ToCamel()
600ML marked this conversation as resolved.
Show resolved Hide resolved
if camel == "CreateTime" || camel == "UpdateTime" {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/model/sql/gen/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func genUpdate(table Table, withCache, postgreSql bool) (string, string, error) {
expressionValues := make([]string, 0)
for _, field := range table.Fields {
camel := field.Name.ToCamel()
camel := stringx.From(field.Name.ReplaceAll("-", "_")).ToCamel()
600ML marked this conversation as resolved.
Show resolved Hide resolved
if camel == "CreateTime" || camel == "UpdateTime" {
continue
}
Expand Down