-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrows.go
58 lines (46 loc) · 981 Bytes
/
rows.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
package driver
import (
"database/sql/driver"
"io"
"google.golang.org/api/iterator"
)
type bigQueryRows struct {
source bigQuerySource
schema bigQuerySchema
}
func (rows *bigQueryRows) ensureSchema() {
if rows.schema == nil {
rows.schema = rows.source.GetSchema()
}
}
func (rows *bigQueryRows) Columns() []string {
rows.ensureSchema()
return rows.schema.ColumnNames()
}
func (rows *bigQueryRows) Close() error {
return nil
}
func (rows *bigQueryRows) Next(dest []driver.Value) error {
rows.ensureSchema()
values, err := rows.source.Next()
if err == iterator.Done {
return io.EOF
}
if err != nil {
return err
}
length := len(values)
for i := range dest {
if i < length {
dest[i], err = rows.schema.ConvertColumnValue(i, values[i])
if err != nil {
return err
}
}
}
return nil
}
func (rows *bigQueryRows) ColumnTypeDatabaseTypeName(index int) string {
rows.ensureSchema()
return rows.schema.ColumnTypeDatabaseTypeName(index)
}