MCPcopy Index your code
hub / github.com/upper/db / fetchRow

Function fetchRow

internal/sqlbuilder/fetch.go:49–91  ·  view source on GitHub ↗

fetchRow receives a *sql.Rows value and tries to map all the rows into a single struct given by the pointer `dst`.

(iter *iterator, dst interface{})

Source from the content-addressed store, hash-verified

47// fetchRow receives a *sql.Rows value and tries to map all the rows into a
48// single struct given by the pointer `dst`.
49func fetchRow(iter *iterator, dst interface{}) error {
50 var columns []string
51 var err error
52
53 rows := iter.cursor
54
55 dstv := reflect.ValueOf(dst)
56
57 if dstv.IsNil() || dstv.Kind() != reflect.Ptr {
58 return ErrExpectingPointer
59 }
60
61 itemV := dstv.Elem()
62
63 if columns, err = rows.Columns(); err != nil {
64 return err
65 }
66
67 reset(dst)
68
69 next := rows.Next()
70
71 if !next {
72 if err = rows.Err(); err != nil {
73 return err
74 }
75 return db.ErrNoMoreRows
76 }
77
78 itemT := itemV.Type()
79 item, err := fetchResult(iter, itemT, columns)
80 if err != nil {
81 return err
82 }
83
84 if itemT.Kind() == reflect.Ptr {
85 itemV.Set(item)
86 } else {
87 itemV.Set(reflect.Indirect(item))
88 }
89
90 return nil
91}
92
93// fetchRows receives a *sql.Rows value and tries to map all the rows into a
94// slice of structs given by the pointer `dst`.

Callers 1

nextMethod · 0.85

Calls 7

resetFunction · 0.85
fetchResultFunction · 0.85
KindMethod · 0.80
ColumnsMethod · 0.65
NextMethod · 0.65
ErrMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected