Scan runs a query with inArgs and provides the rowFunc with the scan function for each row. It handles closing the rows and errors from the result set.
(ctx context.Context, tx *sql.Tx, query string, rowFunc Dest, inArgs ...any)
| 33 | // Scan runs a query with inArgs and provides the rowFunc with the scan function for each row. |
| 34 | // It handles closing the rows and errors from the result set. |
| 35 | func Scan(ctx context.Context, tx *sql.Tx, query string, rowFunc Dest, inArgs ...any) error { |
| 36 | rows, err := tx.QueryContext(ctx, query, inArgs...) |
| 37 | if err != nil { |
| 38 | return err |
| 39 | } |
| 40 | |
| 41 | defer logger.WarnOnError(rows.Close, "Failed to close rows") |
| 42 | |
| 43 | for rows.Next() { |
| 44 | err = rowFunc(rows.Scan) |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return rows.Err() |
| 51 | } |
| 52 | |
| 53 | // Dest is a function that is expected to return the objects to pass to the |
| 54 | // 'dest' argument of sql.Rows.Scan(). It is invoked by SelectObjects once per |
searching dependent graphs…