-
Notifications
You must be signed in to change notification settings - Fork 2
/
scan_func.go
160 lines (150 loc) · 2.7 KB
/
scan_func.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package sq
import (
"github.com/jmoiron/sqlx"
"time"
)
type Scaner func(rows *sqlx.Rows) error
type UintLister interface {
Append(i uint)
}
func ScanUintLister(list UintLister) Scaner {
return func(rows *sqlx.Rows) error {
var item uint
err := rows.Scan(&item)
if err != nil {
return err
}
list.Append(item)
return nil
}
}
type IntLister interface {
Append(i int)
}
func ScanIntLister(list IntLister) Scaner {
return func(rows *sqlx.Rows) error {
var item int
err := rows.Scan(&item)
if err != nil {
return err
}
list.Append(item)
return nil
}
}
type BytesIDLister interface {
Append(data []byte)
}
func ScanBytesLister(list BytesIDLister) Scaner {
return func(rows *sqlx.Rows) error {
var item []byte
err := rows.Scan(&item)
if err != nil {
return err
}
list.Append(item)
return nil
}
}
type StringLister interface {
Append(s string)
}
func ScanStringLister(list StringLister) Scaner {
return func(rows *sqlx.Rows) error {
var item string
err := rows.Scan(&item)
if err != nil {
return err
}
list.Append(item)
return nil
}
}
func ScanBytes(bytes *[][]byte) Scaner {
return func(rows *sqlx.Rows) error {
var item []byte
err := rows.Scan(&item)
if err != nil {
return err
}
*bytes = append(*bytes, item)
return nil
}
}
func ScanStrings(strings *[]string) Scaner {
return func(rows *sqlx.Rows) error {
var item string
err := rows.Scan(&item)
if err != nil {
return err
}
*strings = append(*strings, item)
return nil
}
}
func ScanInts(ints *[]int) Scaner {
return func(rows *sqlx.Rows) error {
var item int
err := rows.Scan(&item)
if err != nil {
return err
}
*ints = append(*ints, item)
return nil
}
}
func ScanUints(ints *[]uint) Scaner {
return func(rows *sqlx.Rows) error {
var item uint
err := rows.Scan(&item)
if err != nil {
return err
}
*ints = append(*ints, item)
return nil
}
}
func ScanInt64s(ints *[]int64) Scaner {
return func(rows *sqlx.Rows) error {
var item int64
err := rows.Scan(&item)
if err != nil {
return err
}
*ints = append(*ints, item)
return nil
}
}
func ScanUint64s(ints *[]uint64) Scaner {
return func(rows *sqlx.Rows) error {
var item uint64
err := rows.Scan(&item)
if err != nil {
return err
}
*ints = append(*ints, item)
return nil
}
}
func ScanBool(bools *[]bool) Scaner {
return func(rows *sqlx.Rows) error {
var item bool
err := rows.Scan(&item)
if err != nil {
return err
}
*bools = append(*bools, item)
return nil
}
}
func ScanTimes(times *[]time.Time) Scaner {
return func(rows *sqlx.Rows) error {
var item time.Time
err := rows.Scan(&item)
if err != nil {
return err
}
*times = append(*times, item)
return nil
}
}