v0.0.46
This commit is contained in:
parent
c60afc89bb
commit
2224db8e85
@ -64,7 +64,7 @@ func (r *StructScanner) StructScanExt(dest any) error {
|
||||
|
||||
v = v.Elem()
|
||||
|
||||
err := fieldsByTraversal(v, r.fields, r.values)
|
||||
err := fieldsByTraversalExtended(v, r.fields, r.values)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -159,7 +159,7 @@ func (r *StructScanner) StructScanBase(dest any) error {
|
||||
|
||||
v = v.Elem()
|
||||
|
||||
err := fieldsByTraversal(v, r.fields, r.values)
|
||||
err := fieldsByTraversalBase(v, r.fields, r.values, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -172,7 +172,7 @@ func (r *StructScanner) StructScanBase(dest any) error {
|
||||
}
|
||||
|
||||
// fieldsByTraversal forked from github.com/jmoiron/sqlx@v1.3.5/sqlx.go
|
||||
func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{}) error {
|
||||
func fieldsByTraversalExtended(v reflect.Value, traversals [][]int, values []interface{}) error {
|
||||
v = reflect.Indirect(v)
|
||||
if v.Kind() != reflect.Struct {
|
||||
return errors.New("argument not a struct")
|
||||
@ -190,6 +190,28 @@ func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{}
|
||||
return nil
|
||||
}
|
||||
|
||||
// fieldsByTraversal forked from github.com/jmoiron/sqlx@v1.3.5/sqlx.go
|
||||
func fieldsByTraversalBase(v reflect.Value, traversals [][]int, values []interface{}, ptrs bool) error {
|
||||
v = reflect.Indirect(v)
|
||||
if v.Kind() != reflect.Struct {
|
||||
return errors.New("argument not a struct")
|
||||
}
|
||||
|
||||
for i, traversal := range traversals {
|
||||
if len(traversal) == 0 {
|
||||
values[i] = new(interface{})
|
||||
continue
|
||||
}
|
||||
f := reflectx.FieldByIndexes(v, traversal)
|
||||
if ptrs {
|
||||
values[i] = f.Addr().Interface()
|
||||
} else {
|
||||
values[i] = f.Interface()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// missingFields forked from github.com/jmoiron/sqlx@v1.3.5/sqlx.go
|
||||
func missingFields(transversals [][]int) (field int, err error) {
|
||||
for i, t := range transversals {
|
||||
|
Loading…
Reference in New Issue
Block a user