Get same as `Select` but it moves the cursor to the first result.
(ctx context.Context, dest interface{}, query string, args ...interface{})
| 100 | |
| 101 | // Get same as `Select` but it moves the cursor to the first result. |
| 102 | func (db *MySQL) Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error { |
| 103 | rows, err := db.Conn.QueryContext(ctx, query, args...) |
| 104 | if err != nil { |
| 105 | return err |
| 106 | } |
| 107 | defer rows.Close() |
| 108 | if !rows.Next() { |
| 109 | return ErrNoRows |
| 110 | } |
| 111 | |
| 112 | if scannable, ok := dest.(Scannable); ok { |
| 113 | return scannable.Scan(rows) |
| 114 | } |
| 115 | |
| 116 | return rows.Scan(dest) |
| 117 | } |
| 118 | |
| 119 | // Exec executes a query. It does not return any rows. |
| 120 | // Use the first output parameter to count the affected rows on UPDATE, INSERT, or DELETE. |