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: do.XXXX struct will not work properly after setting removeFieldPrefix in config.yaml #4112

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cmd/gf/internal/cmd/cmd_z_unit_gen_dao_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func Test_Gen_Dao_Issue3459(t *testing.T) {
in = gendao.CGenDaoInput{
Path: path,
Link: link,
Tables: "",
Tables: "table_user",
TablesEx: "",
Group: group,
Prefix: "",
Expand Down
6 changes: 3 additions & 3 deletions cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Test_Gen_Dao_Default(t *testing.T) {
in = gendao.CGenDaoInput{
Path: path,
Link: link,
Tables: "",
Tables: "table_user",
TablesEx: "",
Group: group,
Prefix: "",
Expand Down Expand Up @@ -139,7 +139,7 @@ func Test_Gen_Dao_TypeMapping(t *testing.T) {
in = gendao.CGenDaoInput{
Path: path,
Link: link,
Tables: "",
Tables: "table_user",
TablesEx: "",
Group: group,
Prefix: "",
Expand Down Expand Up @@ -241,7 +241,7 @@ func Test_Gen_Dao_FieldMapping(t *testing.T) {
in = gendao.CGenDaoInput{
Path: path,
Link: link,
Tables: "",
Tables: "table_user",
TablesEx: "",
Group: group,
Prefix: "",
Expand Down
5 changes: 3 additions & 2 deletions cmd/gf/internal/cmd/gendao/gendao_do.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
)
// replace all types to interface{}.
structDefinition, _ = gregex.ReplaceStringFuncMatch(
"([A-Z]\\w*?)\\s+([\\w\\*\\.]+?)\\s+(//)",
//"([A-Z]\\w*?)\\s+([\\w\\*\\.]+?)\\s+(//)",
"([A-Z]\\w*?)\\s+([\\w\\*\\.]+?)\\s+(`[\\w|:|\"]+?\\s+`)(//)",
structDefinition,
func(match []string) string {
// If the type is already a pointer/slice/map, it does nothing.
if !gstr.HasPrefix(match[2], "*") && !gstr.HasPrefix(match[2], "[]") && !gstr.HasPrefix(match[2], "map") {
return fmt.Sprintf(`%s interface{} %s`, match[1], match[3])
return fmt.Sprintf(`%s interface{} %s %s`, match[1], match[3], match[4])
}
return match[0]
},
Expand Down
10 changes: 5 additions & 5 deletions cmd/gf/internal/cmd/gendao/gendao_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func generateStructFieldDefinition(
err error
localTypeName gdb.LocalType
localTypeNameStr string
jsonTag = gstr.CaseConvert(field.Name, gstr.CaseTypeMatch(in.JsonCase))
jsonTag = gstr.CaseConvert(strings.TrimPrefix(field.Name, in.RemoveFieldPrefix), gstr.CaseTypeMatch(in.JsonCase))
)

if in.TypeMapping != nil && len(in.TypeMapping) > 0 {
Expand Down Expand Up @@ -145,10 +145,10 @@ func generateStructFieldDefinition(
}
attrLines = append(attrLines, fmt.Sprintf(` #%sjson:"%s"`, tagKey, jsonTag))
// orm tag
if !in.IsDo {
// entity
attrLines = append(attrLines, fmt.Sprintf(` #orm:"%s"`, field.Name))
}
//if !in.IsDo {
// entity
attrLines = append(attrLines, fmt.Sprintf(` #orm:"%s"`, field.Name))
//}
attrLines = append(attrLines, fmt.Sprintf(` #description:"%s"%s`, descriptionTag, tagKey))
attrLines = append(attrLines, fmt.Sprintf(` #// %s`, formatComment(field.Comment)))

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/gf/internal/cmd/testdata/issue/2572/sql1.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP TABLE IF EXISTS `user1`;
CREATE TABLE `user1` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'User ID',
`passport` varchar(45) NOT NULL COMMENT 'User Passport',
Expand Down
1 change: 1 addition & 0 deletions cmd/gf/internal/cmd/testdata/issue/2572/sql2.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP TABLE IF EXISTS `user2`;
CREATE TABLE `user2` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'User ID',
`passport` varchar(45) NOT NULL COMMENT 'User Passport',
Expand Down
14 changes: 7 additions & 7 deletions cmd/gf/internal/cmd/testdata/issue/3749/model/do/table_user.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading