Query is a shortcut of executing a query and bind the result to "dst".
(ctx context.Context, db *sql.DB, dst interface{}, query string, args ...interface{})
| 98 | |
| 99 | // Query is a shortcut of executing a query and bind the result to "dst". |
| 100 | func (s *Schema) Query(ctx context.Context, db *sql.DB, dst interface{}, query string, args ...interface{}) error { |
| 101 | rows, err := db.QueryContext(ctx, query, args...) |
| 102 | if err != nil { |
| 103 | return err |
| 104 | } |
| 105 | |
| 106 | if !s.AutoCloseRows { // if not close on bind, we must close it here. |
| 107 | defer rows.Close() |
| 108 | } |
| 109 | |
| 110 | err = s.Bind(dst, rows) |
| 111 | return err |
| 112 | } |
| 113 | |
| 114 | // Bind sets "dst" to the result of "src" and reports any errors. |
| 115 | func (s *Schema) Bind(dst interface{}, src *sql.Rows) error { |