feat: optimize ConvertSliceOfMapToValuesForCreate method

This commit is contained in:
daheige 2021-04-13 22:35:43 +08:00
parent c0b910e7d3
commit ad88cd9a30

View File

@ -42,15 +42,20 @@ func ConvertMapToValuesForCreate(stmt *gorm.Statement, mapValue map[string]inter
func ConvertSliceOfMapToValuesForCreate(stmt *gorm.Statement, mapValues []map[string]interface{}) (values clause.Values) { func ConvertSliceOfMapToValuesForCreate(stmt *gorm.Statement, mapValues []map[string]interface{}) (values clause.Values) {
var ( var (
columns = make([]string, 0, len(mapValues)) columns = make([]string, 0, len(mapValues))
result = map[string][]interface{}{}
selectColumns, restricted = stmt.SelectAndOmitColumns(true, false)
) )
// when the length of mapValues,return directly here
// no need to call stmt.SelectAndOmitColumns method
if len(mapValues) == 0 { if len(mapValues) == 0 {
stmt.AddError(gorm.ErrEmptySlice) stmt.AddError(gorm.ErrEmptySlice)
return return
} }
var (
result = make(map[string][]interface{}, len(mapValues))
selectColumns, restricted = stmt.SelectAndOmitColumns(true, false)
)
for idx, mapValue := range mapValues { for idx, mapValue := range mapValues {
for k, v := range mapValue { for k, v := range mapValue {
if stmt.Schema != nil { if stmt.Schema != nil {