-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.go
69 lines (57 loc) · 1.82 KB
/
result.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
// Copyright (c) 2016 Brandon Buck
package talon
import bolt "github.com/johnnadratowski/golang-neo4j-bolt-driver"
// ResultStats are some details about the results of the query, such as the
// number of of nodes, labels and properties added/set.
type ResultStats struct {
LabelsAdded int64
NodesCreated int64
PropertiesSet int64
NodesDeleted int64
RelationshipsCreated int64
RelationshipsDeleted int64
}
// Result represents a return from a non-row based query like a create/delete
// or upate where you're not using something like "return" in the query.
type Result struct {
Stats ResultStats
Type string
}
// Close exits primarly to match Rows return behavior. When you run `Query`
// you have to close the rows object yourself. This is just here to prevent
// breakages.
func Close() { /* noop */ }
func wrapBoltResult(r bolt.Result) *Result {
md := r.Metadata()
res := &Result{
Type: maybeFetchString(md, "type"),
Stats: ResultStats{},
}
if stats, ok := md["stats"].(map[string]interface{}); ok {
res.Stats.LabelsAdded = maybeFetchInt64(stats, "labels-added")
res.Stats.NodesCreated = maybeFetchInt64(stats, "nodes-created")
res.Stats.PropertiesSet = maybeFetchInt64(stats, "properties-set")
res.Stats.NodesDeleted = maybeFetchInt64(stats, "nodes-deleted")
res.Stats.RelationshipsCreated = maybeFetchInt64(stats, "relationships-created")
res.Stats.RelationshipsDeleted = maybeFetchInt64(stats, "relationships-deleted")
}
return res
}
func maybeFetchInt64(m map[string]interface{}, k string) int64 {
if val, ok := m[k]; ok {
var i64 int64
if i64, ok = val.(int64); ok {
return i64
}
}
return 0
}
func maybeFetchString(m map[string]interface{}, k string) string {
if val, ok := m[k]; ok {
var str string
if str, ok = val.(string); ok {
return str
}
}
return ""
}