model_scan.go
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package orm
import (
"fmt"
"reflect"
"github.com/go-pg/pg/types"
)
type scanValuesModel struct {
Discard
values []interface{}
}
var _ Model = scanValuesModel{}
func Scan(values ...interface{}) scanValuesModel {
return scanValuesModel{
values: values,
}
}
func (scanValuesModel) useQueryOne() bool {
return true
}
func (m scanValuesModel) NewModel() ColumnScanner {
return m
}
func (m scanValuesModel) ScanColumn(colIdx int, colName string, rd types.Reader, n int) error {
if colIdx >= len(m.values) {
return fmt.Errorf("pg: no Scan var for column index=%d name=%q",
colIdx, colName)
}
return types.Scan(m.values[colIdx], rd, n)
}
//------------------------------------------------------------------------------
type scanReflectValuesModel struct {
Discard
values []reflect.Value
}
var _ Model = scanReflectValuesModel{}
func scanReflectValues(values []reflect.Value) scanReflectValuesModel {
return scanReflectValuesModel{
values: values,
}
}
func (scanReflectValuesModel) useQueryOne() bool {
return true
}
func (m scanReflectValuesModel) NewModel() ColumnScanner {
return m
}
func (m scanReflectValuesModel) ScanColumn(colIdx int, colName string, rd types.Reader, n int) error {
if colIdx >= len(m.values) {
return fmt.Errorf("pg: no Scan var for column index=%d name=%q",
colIdx, colName)
}
return types.ScanValue(m.values[colIdx], rd, n)
}