MCPcopy
hub / github.com/jmoiron/sqlx / fieldsByTraversal

Function fieldsByTraversal

sqlx.go:1026–1045  ·  view source on GitHub ↗

fieldsByName fills a values interface with fields from the passed value based on the traversals in int. If ptrs is true, return addresses instead of values. We write this instead of using FieldsByName to save allocations and map lookups when iterating over many rows. Empty traversals will get an i

(v reflect.Value, traversals [][]int, values []interface{}, ptrs bool)

Source from the content-addressed store, hash-verified

1024// Because of the necessity of requesting ptrs or values, it's considered a bit too
1025// specialized for inclusion in reflectx itself.
1026func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{}, ptrs bool) error {
1027 v = reflect.Indirect(v)
1028 if v.Kind() != reflect.Struct {
1029 return errors.New("argument not a struct")
1030 }
1031
1032 for i, traversal := range traversals {
1033 if len(traversal) == 0 {
1034 values[i] = new(interface{})
1035 continue
1036 }
1037 f := reflectx.FieldByIndexes(v, traversal)
1038 if ptrs {
1039 values[i] = f.Addr().Interface()
1040 } else {
1041 values[i] = f.Interface()
1042 }
1043 }
1044 return nil
1045}
1046
1047func missingFields(transversals [][]int) (field int, err error) {
1048 for i, t := range transversals {

Callers 3

StructScanMethod · 0.85
scanAnyMethod · 0.85
scanAllFunction · 0.85

Calls 2

FieldByIndexesFunction · 0.92
KindMethod · 0.80

Tested by

no test coverage detected