Skip to content

Commit d760184

Browse files
committed
Apply code review suggestions from cespare
1 parent b1416de commit d760184

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

bind.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,26 @@ func rebindBuff(bindType int, query string) string {
9898
return rqb.String()
9999
}
100100

101-
func asSliceToExpand(i interface{}) (v reflect.Value, ok bool) {
101+
func asSliceForIn(i interface{}) (v reflect.Value, ok bool) {
102102
if i == nil {
103-
ok = false
104-
return
103+
return reflect.Value{}, false
105104
}
106105

107106
v = reflect.ValueOf(i)
108107
t := reflectx.Deref(v.Type())
109108

109+
// Only expand slices
110+
if t.Kind() != reflect.Slice {
111+
return reflect.Value{}, false
112+
}
113+
110114
// []byte is a driver.Value type so it should not be expanded
111-
ok = t.Kind() == reflect.Slice && t != reflect.TypeOf([]byte{})
115+
if t == reflect.TypeOf([]byte{}) {
116+
return reflect.Value{}, false
112117

113-
if !ok {
114-
// Don't return non-expandable values
115-
v = reflect.Value{}
116118
}
117119

118-
return
120+
return v, true
119121
}
120122

121123
// In expands slice values in args, returning the modified query string
@@ -140,7 +142,7 @@ func In(query string, args ...interface{}) (string, []interface{}, error) {
140142
arg, _ = a.Value()
141143
}
142144

143-
if v, ok := asSliceToExpand(arg); ok {
145+
if v, ok := asSliceForIn(arg); ok {
144146
meta[i].length = v.Len()
145147
meta[i].v = v
146148

0 commit comments

Comments
 (0)