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

drivers/pgsql:pgsql returning id should use quotation marks,when primary key is capital #3637

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions cmd/gf/internal/cmd/gendao/gendao.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ CONFIGURATION SUPPORT
CGenDaoBriefClear = `delete all generated go files that do not exist in database`
CGenDaoBriefTypeMapping = `custom local type mapping for generated struct attributes relevant to fields of table`
CGenDaoBriefFieldMapping = `custom local type mapping for generated struct attributes relevant to specific fields of table`
CGenDaoBriefWithPathPackage = `is should make the dao package by the path`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些修改与 #3618 重复,建议从主分支新开分支单独修改pgsqlRETURNING "ID"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用新的分支提交了,现在只有一个commit了
新pr是 #3638

CGenDaoBriefGroup = `
specifying the configuration group name of database for generated ORM instance,
it's not necessary and the default value is "default"
Expand Down Expand Up @@ -118,6 +119,7 @@ generated json tag case for model struct, cases are as follows:
tplVarGroupName = `{TplGroupName}`
tplVarDatetimeStr = `{TplDatetimeStr}`
tplVarCreatedAtDatetimeStr = `{TplCreatedAtDatetimeStr}`
tplVarPackageName = `{TplPackageName}`
)

var (
Expand Down Expand Up @@ -174,6 +176,7 @@ func init() {
`CGenDaoBriefTplDaoInternalPath`: CGenDaoBriefTplDaoInternalPath,
`CGenDaoBriefTplDaoDoPathPath`: CGenDaoBriefTplDaoDoPathPath,
`CGenDaoBriefTplDaoEntityPath`: CGenDaoBriefTplDaoEntityPath,
`CGenDaoBriefWithPathPackage`: CGenDaoBriefWithPathPackage,
})
}

Expand Down Expand Up @@ -206,6 +209,7 @@ type (
NoJsonTag bool `name:"noJsonTag" short:"k" brief:"{CGenDaoBriefNoJsonTag}" orphan:"true"`
NoModelComment bool `name:"noModelComment" short:"m" brief:"{CGenDaoBriefNoModelComment}" orphan:"true"`
Clear bool `name:"clear" short:"a" brief:"{CGenDaoBriefClear}" orphan:"true"`
WithPathPackage bool `name:"withPathPackage" short:"wp" brief:"{CGenDaoBriefWithPathPackage}" orphan:"true"`

TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenDaoBriefTypeMapping}" orphan:"true"`
FieldMapping map[DBTableFieldName]CustomAttributeType `name:"fieldMapping" short:"fm" brief:"{CGenDaoBriefFieldMapping}" orphan:"true"`
Expand Down
5 changes: 5 additions & 0 deletions cmd/gf/internal/cmd/gendao/gendao_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ type generateDaoIndexInput struct {
}

func generateDaoIndex(in generateDaoIndexInput) {
daoPackage := "dao"
if in.WithPathPackage {
daoPackage = filepath.Base(in.DaoPath)
}
path := filepath.FromSlash(gfile.Join(in.DirPathDao, in.FileName+".go"))
// It should add path to result slice whenever it would generate the path file or not.
in.genItems.AppendGeneratedFilePath(path)
Expand All @@ -116,6 +120,7 @@ func generateDaoIndex(in generateDaoIndexInput) {
tplVarTableName: in.TableName,
tplVarTableNameCamelCase: in.TableNameCamelCase,
tplVarTableNameCamelLowerCase: in.TableNameCamelLowerCase,
tplVarPackageName: daoPackage,
})
indexContent = replaceDefaultVar(in.CGenDaoInternalInput, indexContent)
if err := gfile.PutContents(path, strings.TrimSpace(indexContent)); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions cmd/gf/internal/cmd/gendao/gendao_do.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
func generateDoContent(
ctx context.Context, in CGenDaoInternalInput, tableName, tableNameCamelCase, structDefine string,
) string {
doPackage := "do"
if in.WithPathPackage {
doPackage = filepath.Base(in.DoPath)
}
doContent := gstr.ReplaceByMap(
getTemplateFromPathOrDefault(in.TplDaoDoPath, consts.TemplateGenDaoDoContent),
g.MapStrStr{
tplVarTableName: tableName,
tplVarPackageImports: getImportPartContent(ctx, structDefine, true, nil),
tplVarTableNameCamelCase: tableNameCamelCase,
tplVarStructDefine: structDefine,
tplVarPackageName: doPackage,
},
)
doContent = replaceDefaultVar(in, doContent)
Expand Down
5 changes: 5 additions & 0 deletions cmd/gf/internal/cmd/gendao/gendao_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,18 @@ func generateEntity(ctx context.Context, in CGenDaoInternalInput) {
func generateEntityContent(
ctx context.Context, in CGenDaoInternalInput, tableName, tableNameCamelCase, structDefine string, appendImports []string,
) string {
entityPackage := "entity"
if in.WithPathPackage {
entityPackage = filepath.Base(in.EntityPath)
}
entityContent := gstr.ReplaceByMap(
getTemplateFromPathOrDefault(in.TplDaoEntityPath, consts.TemplateGenDaoEntityContent),
g.MapStrStr{
tplVarTableName: tableName,
tplVarPackageImports: getImportPartContent(ctx, structDefine, false, appendImports),
tplVarTableNameCamelCase: tableNameCamelCase,
tplVarStructDefine: structDefine,
tplVarPackageName: entityPackage,
},
)
entityContent = replaceDefaultVar(in, entityContent)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gf/internal/consts/consts_gen_dao_template_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const TemplateGenDaoIndexContent = `
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================

package dao
package {TplPackageName}

import (
"{TplImportPrefix}/internal"
Expand Down
2 changes: 1 addition & 1 deletion cmd/gf/internal/consts/consts_gen_dao_template_do.go

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

2 changes: 1 addition & 1 deletion cmd/gf/internal/consts/consts_gen_dao_template_entity.go

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

3 changes: 2 additions & 1 deletion contrib/drivers/pgsql/pgsql_do_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package pgsql
import (
"context"
"database/sql"
"fmt"
"strings"

"github.com/gogf/gf/v2/database/gdb"
Expand Down Expand Up @@ -55,7 +56,7 @@ func (d *Driver) DoExec(ctx context.Context, link gdb.Link, sql string, args ...
// check if it is an insert operation.
if !isUseCoreDoExec && pkField.Name != "" && strings.Contains(sql, "INSERT INTO") {
primaryKey = pkField.Name
sql += " RETURNING " + primaryKey
sql += fmt.Sprintf(` RETURNING "%s"`, primaryKey)
} else {
// use default DoExec
return d.Core.DoExec(ctx, link, sql, args...)
Expand Down