-
Notifications
You must be signed in to change notification settings - Fork 1
/
row.go
62 lines (52 loc) · 1009 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
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
package row
import (
"github.com/gotodb/gotodb/datatype"
)
type Row struct {
Keys []interface{}
Vals []interface{}
}
type Reader func() (*Row, error)
func NewRow(vals ...interface{}) *Row {
colNum := 0
if vals != nil {
colNum = len(vals)
}
res := &Row{
Keys: []interface{}{},
Vals: make([]interface{}, colNum),
}
for i := 0; i < colNum; i++ {
res.Vals[i] = vals[i]
}
return res
}
func (r *Row) GetKeyString() string {
res := ""
if r.Keys == nil {
r.Keys = []interface{}{}
}
for _, key := range r.Keys {
res += datatype.ToKeyString(key) + ":"
}
return res
}
func (r *Row) AppendKeys(keys ...interface{}) *Row {
r.Keys = append(r.Keys, keys...)
return r
}
func (r *Row) AppendVals(vals ...interface{}) *Row {
r.Vals = append(r.Vals, vals...)
return r
}
func (r *Row) AppendRow(row *Row) *Row {
r.Vals = append(r.Vals, row.Vals...)
return r
}
func (r *Row) ClearKeys() {
r.Keys = []interface{}{}
}
func (r *Row) Clear() {
r.Keys = r.Keys[:0]
r.Vals = r.Vals[:0]
}