SliceScan a row, returning a []interface{} with values similar to MapScan. This function is primarily intended for use where the number of columns is not known. Because you can pass an []interface{} directly to Scan, it's recommended that you do that as it will not have to allocate new slices per r
(r ColScanner)
| 803 | // it's recommended that you do that as it will not have to allocate new |
| 804 | // slices per row. |
| 805 | func SliceScan(r ColScanner) ([]interface{}, error) { |
| 806 | // ignore r.started, since we needn't use reflect for anything. |
| 807 | columns, err := r.Columns() |
| 808 | if err != nil { |
| 809 | return []interface{}{}, err |
| 810 | } |
| 811 | |
| 812 | values := make([]interface{}, len(columns)) |
| 813 | for i := range values { |
| 814 | values[i] = new(interface{}) |
| 815 | } |
| 816 | |
| 817 | err = r.Scan(values...) |
| 818 | |
| 819 | if err != nil { |
| 820 | return values, err |
| 821 | } |
| 822 | |
| 823 | for i := range columns { |
| 824 | values[i] = *(values[i].(*interface{})) |
| 825 | } |
| 826 | |
| 827 | return values, r.Err() |
| 828 | } |
| 829 | |
| 830 | // MapScan scans a single Row into the dest map[string]interface{}. |
| 831 | // Use this to get results for SQL that might not be under your control |