diff --git a/named.go b/named.go index 728aa04d..9bcd7800 100644 --- a/named.go +++ b/named.go @@ -277,7 +277,7 @@ func bindArray(bindType int, query string, arg interface{}, m *reflectx.Mapper) if err != nil { return "", []interface{}{}, err } - arrayValue := reflect.ValueOf(arg) + arrayValue := reflect.Indirect(reflect.ValueOf(arg)) arrayLen := arrayValue.Len() if arrayLen == 0 { return "", []interface{}{}, fmt.Errorf("length of array is 0: %#v", arg) @@ -421,6 +421,11 @@ func Named(query string, arg interface{}) (string, []interface{}, error) { func bindNamedMapper(bindType int, query string, arg interface{}, m *reflectx.Mapper) (string, []interface{}, error) { t := reflect.TypeOf(arg) k := t.Kind() + + if k == reflect.Ptr { + k = t.Elem().Kind() + } + switch { case k == reflect.Map && t.Key().Kind() == reflect.String: m, ok := convertMapStringInterface(arg) diff --git a/named_test.go b/named_test.go index 8481b35b..26031389 100644 --- a/named_test.go +++ b/named_test.go @@ -211,6 +211,10 @@ func TestNamedQueries(t *testing.T) { _, err = db.NamedExec(insert, sls) test.Error(err) + // and test ptr batch inserts + _, err = db.NamedExec(insert, &sls) + test.Error(err) + // test map batch inserts slsMap := []map[string]interface{}{ {"first_name": "Ardie", "last_name": "Savea", "email": "asavea@ab.co.nz"},