QueryRows executes query and streams row values through assign. The returned duration measures query submission latency (QueryContext call).
(ctx context.Context, q Queryer, query string, assign AssignFunc, args ...any)
| 19 | // QueryRows executes query and streams row values through assign. |
| 20 | // The returned duration measures query submission latency (QueryContext call). |
| 21 | func QueryRows(ctx context.Context, q Queryer, query string, assign AssignFunc, args ...any) (time.Duration, error) { |
| 22 | start := time.Now() |
| 23 | rows, err := q.QueryContext(ctx, query, args...) |
| 24 | queryDuration := time.Since(start) |
| 25 | if err != nil { |
| 26 | return 0, err |
| 27 | } |
| 28 | defer func() { _ = rows.Close() }() |
| 29 | if err := readRows(rows, assign); err != nil { |
| 30 | return queryDuration, err |
| 31 | } |
| 32 | return queryDuration, nil |
| 33 | } |
| 34 | |
| 35 | // readRows scans all rows and invokes assign for every column value. |
| 36 | func readRows(rows *sql.Rows, assign AssignFunc) error { |
searching dependent graphs…