toInterfaceArguments converts the given value into an array of interfaces.
(value interface{})
| 92 | |
| 93 | // toInterfaceArguments converts the given value into an array of interfaces. |
| 94 | func 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. |
no test coverage detected