-
Notifications
You must be signed in to change notification settings - Fork 0
/
row.go
35 lines (30 loc) · 825 Bytes
/
row.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
package hake
import (
"cloud.google.com/go/spanner"
gspanner "google.golang.org/genproto/googleapis/spanner/v1"
)
// Columns returns columns of the row as []*spanner.GenericColumnValue.
func Columns(row *spanner.Row) ([]*spanner.GenericColumnValue, error) {
names := row.ColumnNames()
cols := make([]*spanner.GenericColumnValue, 0, len(names))
for _, n := range names {
var col spanner.GenericColumnValue
if err := row.ColumnByName(n, &col); err != nil {
return nil, err
}
cols = append(cols, &col)
}
return cols, nil
}
// Types returns column types of the row.
func Types(row *spanner.Row) ([]*gspanner.Type, error) {
cols, err := Columns(row)
if err != nil {
return nil, err
}
types := make([]*gspanner.Type, len(cols))
for i, col := range cols {
types[i] = col.Type
}
return types, nil
}