bindArray binds a named parameter query with fields from an array or slice of structs argument.
(bindType int, query string, arg interface{}, m *reflectx.Mapper)
| 271 | // bindArray binds a named parameter query with fields from an array or slice of |
| 272 | // structs argument. |
| 273 | func bindArray(bindType int, query string, arg interface{}, m *reflectx.Mapper) (string, []interface{}, error) { |
| 274 | // do the initial binding with QUESTION; if bindType is not question, |
| 275 | // we can rebind it at the end. |
| 276 | bound, names, err := compileNamedQuery([]byte(query), QUESTION) |
| 277 | if err != nil { |
| 278 | return "", []interface{}{}, err |
| 279 | } |
| 280 | arrayValue := reflect.ValueOf(arg) |
| 281 | arrayLen := arrayValue.Len() |
| 282 | if arrayLen == 0 { |
| 283 | return "", []interface{}{}, fmt.Errorf("length of array is 0: %#v", arg) |
| 284 | } |
| 285 | var arglist = make([]interface{}, 0, len(names)*arrayLen) |
| 286 | for i := 0; i < arrayLen; i++ { |
| 287 | elemArglist, err := bindAnyArgs(names, arrayValue.Index(i).Interface(), m) |
| 288 | if err != nil { |
| 289 | return "", []interface{}{}, err |
| 290 | } |
| 291 | arglist = append(arglist, elemArglist...) |
| 292 | } |
| 293 | if arrayLen > 1 { |
| 294 | bound = fixBound(bound, arrayLen) |
| 295 | } |
| 296 | // adjust binding type if we weren't on question |
| 297 | if bindType != QUESTION { |
| 298 | bound = Rebind(bindType, bound) |
| 299 | } |
| 300 | return bound, arglist, nil |
| 301 | } |
| 302 | |
| 303 | // bindMap binds a named parameter query with a map of arguments. |
| 304 | func bindMap(bindType int, query string, args map[string]interface{}) (string, []interface{}, error) { |
no test coverage detected