mirror of https://github.com/go-gorm/gorm.git
Use tableName.field or tableName.* in returning string
This commit is contained in:
parent
0fa1335555
commit
21f4de584f
|
@ -34,17 +34,17 @@ func Create(scope *Scope) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
returningField := ""
|
returningKey := "*"
|
||||||
if scope.PrimaryKey() == "" {
|
if scope.PrimaryKey() == "" {
|
||||||
returningField = "*"
|
returningKey = "*"
|
||||||
} else {
|
} else {
|
||||||
returningField = scope.PrimaryKey()
|
returningKey = scope.PrimaryKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(columns) == 0 {
|
if len(columns) == 0 {
|
||||||
scope.Raw(fmt.Sprintf("INSERT INTO %v DEFAULT VALUES %v",
|
scope.Raw(fmt.Sprintf("INSERT INTO %v DEFAULT VALUES %v",
|
||||||
scope.QuotedTableName(),
|
scope.QuotedTableName(),
|
||||||
scope.Dialect().ReturningStr(returningField),
|
scope.Dialect().ReturningStr(scope.TableName(), returningKey),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
scope.Raw(fmt.Sprintf(
|
scope.Raw(fmt.Sprintf(
|
||||||
|
@ -52,7 +52,7 @@ func Create(scope *Scope) {
|
||||||
scope.QuotedTableName(),
|
scope.QuotedTableName(),
|
||||||
strings.Join(columns, ","),
|
strings.Join(columns, ","),
|
||||||
strings.Join(sqls, ","),
|
strings.Join(sqls, ","),
|
||||||
scope.Dialect().ReturningStr(returningField),
|
scope.Dialect().ReturningStr(scope.TableName(), returningKey),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (s *commonDialect) PrimaryKeyTag(value reflect.Value, size int) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *commonDialect) ReturningStr(key string) string {
|
func (s *commonDialect) ReturningStr(tableName, key string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ type Dialect interface {
|
||||||
HasTop() bool
|
HasTop() bool
|
||||||
SqlTag(value reflect.Value, size int) string
|
SqlTag(value reflect.Value, size int) string
|
||||||
PrimaryKeyTag(value reflect.Value, size int) string
|
PrimaryKeyTag(value reflect.Value, size int) string
|
||||||
ReturningStr(key string) string
|
ReturningStr(tableName, key string) string
|
||||||
SelectFromDummyTable() string
|
SelectFromDummyTable() string
|
||||||
Quote(key string) string
|
Quote(key string) string
|
||||||
HasTable(scope *Scope, tableName string) bool
|
HasTable(scope *Scope, tableName string) bool
|
||||||
|
|
2
mssql.go
2
mssql.go
|
@ -64,7 +64,7 @@ func (s *mssql) PrimaryKeyTag(value reflect.Value, size int) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *mssql) ReturningStr(key string) string {
|
func (s *mssql) ReturningStr(tableName, key string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
mysql.go
4
mysql.go
|
@ -2,8 +2,8 @@ package gorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mysql struct{}
|
type mysql struct{}
|
||||||
|
@ -64,7 +64,7 @@ func (s *mysql) PrimaryKeyTag(value reflect.Value, size int) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *mysql) ReturningStr(key string) string {
|
func (s *mysql) ReturningStr(tableName, key string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
|
||||||
"github.com/lib/pq/hstore"
|
"github.com/lib/pq/hstore"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type postgres struct {
|
type postgres struct {
|
||||||
|
@ -65,8 +65,8 @@ func (s *postgres) PrimaryKeyTag(value reflect.Value, size int) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *postgres) ReturningStr(key string) string {
|
func (s *postgres) ReturningStr(tableName, key string) string {
|
||||||
return fmt.Sprintf("RETURNING \"%v\"", key)
|
return fmt.Sprintf("RETURNING %v.%v", tableName, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *postgres) SelectFromDummyTable() string {
|
func (s *postgres) SelectFromDummyTable() string {
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (s *sqlite3) PrimaryKeyTag(value reflect.Value, size int) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sqlite3) ReturningStr(key string) string {
|
func (s *sqlite3) ReturningStr(tableName, key string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue