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

Method scanAny

sqlx.go:740–793  ·  view source on GitHub ↗
(dest interface{}, structOnly bool)

Source from the content-addressed store, hash-verified

738}
739
740func (r *Row) scanAny(dest interface{}, structOnly bool) error {
741 if r.err != nil {
742 return r.err
743 }
744 if r.rows == nil {
745 r.err = sql.ErrNoRows
746 return r.err
747 }
748 defer r.rows.Close()
749
750 v := reflect.ValueOf(dest)
751 if v.Kind() != reflect.Ptr {
752 return errors.New("must pass a pointer, not a value, to StructScan destination")
753 }
754 if v.IsNil() {
755 return errors.New("nil pointer passed to StructScan destination")
756 }
757
758 base := reflectx.Deref(v.Type())
759 scannable := isScannable(base)
760
761 if structOnly && scannable {
762 return structOnlyError(base)
763 }
764
765 columns, err := r.Columns()
766 if err != nil {
767 return err
768 }
769
770 if scannable && len(columns) > 1 {
771 return fmt.Errorf("scannable dest type %s with >1 columns (%d) in result", base.Kind(), len(columns))
772 }
773
774 if scannable {
775 return r.Scan(dest)
776 }
777
778 m := r.Mapper
779
780 fields := m.TraversalsByName(v.Type(), columns)
781 // if we are not unsafe and are missing fields, return an error
782 if f, err := missingFields(fields); err != nil && !r.unsafe {
783 return fmt.Errorf("missing destination name %s in %T", columns[f], dest)
784 }
785 values := make([]interface{}, len(columns))
786
787 err = fieldsByTraversal(v, fields, values, true)
788 if err != nil {
789 return err
790 }
791 // scan into the struct field pointers and append to our results
792 return r.Scan(values...)
793}
794
795// StructScan a single Row into dest.
796func (r *Row) StructScan(dest interface{}) error {

Callers 5

StructScanMethod · 0.95
GetFunction · 0.80
GetContextFunction · 0.80
GetContextMethod · 0.80
GetMethod · 0.80

Calls 11

ColumnsMethod · 0.95
ScanMethod · 0.95
DerefFunction · 0.92
isScannableFunction · 0.85
structOnlyErrorFunction · 0.85
missingFieldsFunction · 0.85
fieldsByTraversalFunction · 0.85
KindMethod · 0.80
ErrorfMethod · 0.80
TraversalsByNameMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected