Skip to content

Commit

Permalink
Merge pull request #632 from GSokol/small_performance_improvement_for…
Browse files Browse the repository at this point in the history
…_batch_insert

Small performance improvement for batch insert
  • Loading branch information
jmoiron committed Jun 13, 2020
2 parents 53323b7 + 056d01c commit 2cb55b2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions named.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func bindArray(bindType int, query string, arg interface{}, m *reflectx.Mapper)
if arrayLen == 0 {
return "", []interface{}{}, fmt.Errorf("length of array is 0: %#v", arg)
}
var arglist []interface{}
var arglist = make([]interface{}, 0, len(names)*arrayLen)
for i := 0; i < arrayLen; i++ {
elemArglist, err := bindAnyArgs(names, arrayValue.Index(i).Interface(), m)
if err != nil {
Expand Down Expand Up @@ -379,11 +379,12 @@ func Named(query string, arg interface{}) (string, []interface{}, error) {
}

func bindNamedMapper(bindType int, query string, arg interface{}, m *reflectx.Mapper) (string, []interface{}, error) {
if maparg, ok := arg.(map[string]interface{}); ok {
return bindMap(bindType, query, maparg)
}
switch reflect.TypeOf(arg).Kind() {
case reflect.Array, reflect.Slice:
t := reflect.TypeOf(arg)
k := t.Kind()
switch {
case k == reflect.Map && t.Key().Kind() == reflect.String:
return bindMap(bindType, query, arg.(map[string]interface{}))
case k == reflect.Array || k == reflect.Slice:
return bindArray(bindType, query, arg, m)
default:
return bindStruct(bindType, query, arg, m)
Expand Down

0 comments on commit 2cb55b2

Please sign in to comment.