MCPcopy Index your code
hub / github.com/upper/db / toInterfaceArguments

Function toInterfaceArguments

internal/sqlbuilder/convert.go:94–122  ·  view source on GitHub ↗

toInterfaceArguments converts the given value into an array of interfaces.

(value interface{})

Source from the content-addressed store, hash-verified

92
93// toInterfaceArguments converts the given value into an array of interfaces.
94func toInterfaceArguments(value interface{}) (args []interface{}, isSlice bool) {
95 if value == nil {
96 return nil, false
97 }
98
99 switch t := value.(type) {
100 case driver.Valuer:
101 return []interface{}{t}, false
102 }
103
104 v := reflect.ValueOf(value)
105 if v.Type().Kind() == reflect.Slice {
106 var i, total int
107
108 // Byte slice gets transformed into a string.
109 if v.Type().Elem().Kind() == reflect.Uint8 {
110 return []interface{}{string(v.Bytes())}, false
111 }
112
113 total = v.Len()
114 args = make([]interface{}, total)
115 for i = 0; i < total; i++ {
116 args[i] = v.Index(i).Interface()
117 }
118 return args, true
119 }
120
121 return []interface{}{value}, false
122}
123
124// toColumnsValuesAndArguments maps the given columnNames and columnValues into
125// expr's Columns and Values, it also extracts and returns query arguments.

Callers 3

expandArgumentFunction · 0.85
cmpMethod · 0.85
PlaceholderValueMethod · 0.85

Calls 2

KindMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected