update 支持postgres RETURNING 语法

This commit is contained in:
wanliping 2020-11-27 13:09:44 +00:00
parent 22c2027a30
commit fc871d266e
2 changed files with 10 additions and 1 deletions

View File

@ -66,7 +66,10 @@ func Update(db *gorm.DB) {
} else {
return
}
db.Statement.Build("UPDATE", "SET", "WHERE", "RETURNING")
db.Statement.Build("UPDATE", "SET", "WHERE")
if db.Dialector.Name() == "postgres" {
db.Statement.Build("RETURNING")
}
}
if _, ok := db.Statement.Clauses["WHERE"]; !db.AllowGlobalUpdate && !ok {

View File

@ -11,6 +11,12 @@ func (returning Returning) Name() string {
// Build build where clause
func (returning Returning) Build(builder Builder) {
for _, column := range returning.Columns {
if column.Name == "*" {
builder.WriteByte('*')
return
}
}
for idx, column := range returning.Columns {
if idx > 0 {
builder.WriteByte(',')