MCPcopy
hub / github.com/jmoiron/sqlx / SliceScan

Function SliceScan

sqlx.go:805–828  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

803// it's recommended that you do that as it will not have to allocate new
804// slices per row.
805func 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

Callers 2

SliceScanMethod · 0.85
SliceScanMethod · 0.85

Calls 3

ColumnsMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected