feat: optimize ConvertSliceOfMapToValuesForCreate method
This commit is contained in:
parent
c0b910e7d3
commit
ad88cd9a30
@ -41,16 +41,21 @@ func ConvertMapToValuesForCreate(stmt *gorm.Statement, mapValue map[string]inter
|
|||||||
// ConvertSliceOfMapToValuesForCreate convert slice of map to values
|
// ConvertSliceOfMapToValuesForCreate convert slice of map to values
|
||||||
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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user