SelectObjects executes a statement which must yield rows with a specific columns schema. It invokes the given Dest hook for each yielded row.
(ctx context.Context, stmt *sql.Stmt, rowFunc Dest, args ...any)
| 13 | // SelectObjects executes a statement which must yield rows with a specific |
| 14 | // columns schema. It invokes the given Dest hook for each yielded row. |
| 15 | func SelectObjects(ctx context.Context, stmt *sql.Stmt, rowFunc Dest, args ...any) error { |
| 16 | rows, err := stmt.QueryContext(ctx, args...) |
| 17 | if err != nil { |
| 18 | return err |
| 19 | } |
| 20 | |
| 21 | defer logger.WarnOnError(rows.Close, "Failed to close rows") |
| 22 | |
| 23 | for rows.Next() { |
| 24 | err = rowFunc(rows.Scan) |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return rows.Err() |
| 31 | } |
| 32 | |
| 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. |
searching dependent graphs…