-
Notifications
You must be signed in to change notification settings - Fork 0
/
rows.go
82 lines (67 loc) · 1.59 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2016 Brandon Buck
package talon
import (
"errors"
bolt "github.com/johnnadratowski/golang-neo4j-bolt-driver"
boltGraph "github.com/johnnadratowski/golang-neo4j-bolt-driver/structures/graph"
)
// &{
// metadata: map[
// fields:[n]
// ]
// statement: 0xc420430000
// closed: false
// consumed: true
// finishedConsume: false
// pipelineIndex: 0
// closeStatement: true
// }
// Metadata contains details about the rows response, such as the field names
// from the query.
type Metadata struct {
Fields []string
}
func metadataFromBoltRows(rows bolt.Rows) *Metadata {
md := rows.Metadata()
mdFields := md["fields"].([]interface{})
fields := make([]string, len(mdFields))
for i := 0; i < len(fields); i++ {
fields[i] = mdFields[i].(string)
}
return &Metadata{
Fields: fields,
}
}
type Row []Entity
type Rows struct {
Metadata *Metadata
Columns []string
boltRows bolt.Rows
}
func wrapBoltRows(rs bolt.Rows) *Rows {
return &Rows{
Metadata: metadataFromBoltRows(rs),
boltRows: rs,
}
}
func (r *Rows) Close() {
r.boltRows.Close()
}
func (r *Rows) Next() (Row, error) {
boltRow, _, err := r.boltRows.NextNeo()
row := make(Row, len(boltRow))
for i := 0; i < len(row); i++ {
if node, ok := boltRow[i].(boltGraph.Node); ok {
row[i] = wrapBoltNode(node)
} else if rel, ok := boltRow[i].(boltGraph.Relationship); ok {
row[i] = wrapBoltRelationship(rel)
} else {
// TODO: Remove
panic(errors.New("this doesn't happen!!!"))
}
}
return row, err
}
func (r *Rows) All() ([][]interface{}, map[string]interface{}, error) {
return r.boltRows.All()
}