-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
96 lines (80 loc) · 1.51 KB
/
node.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2016 Brandon Buck
package talon
import (
"github.com/bbuck/talon/types"
bolt "github.com/johnnadratowski/golang-neo4j-bolt-driver/structures/graph"
)
type Node struct {
ID int64
Labels []string
Properties types.Properties
}
func wrapBoltNode(n bolt.Node) *Node {
return &Node{
ID: n.NodeIdentity,
Labels: n.Labels,
Properties: types.Properties(n.Properties),
}
}
func (*Node) Type() EntityType {
return EntityNode
}
func (n *Node) Get(key string) (val interface{}, ok bool) {
val, ok = n.Properties[key]
return
}
func (n *Node) GetString(key string) (string, bool) {
val, ok := n.Get(key)
if ok {
switch str := val.(type) {
case string:
return str, ok
case *string:
return *str, ok
}
}
return "", ok
}
func (n *Node) GetInt(key string) (int64, bool) {
val, ok := n.Get(key)
if ok {
switch i := val.(type) {
case int:
return int64(i), ok
case int8:
return int64(i), ok
case int16:
return int64(i), ok
case int32:
return int64(i), ok
case int64:
return i, ok
}
}
return 0, ok
}
func (n *Node) GetFloat(key string) (float64, bool) {
val, ok := n.Get(key)
if ok {
switch f := val.(type) {
case float32:
return float64(f), ok
case float64:
return f, ok
}
}
return 0, ok
}
func (n *Node) GetBool(key string) (bool, bool) {
val, ok := n.Get(key)
if ok {
switch b := val.(type) {
case bool:
return b, ok
}
}
return false, ok
}
func (n *Node) Set(key string, val interface{}) {
n.Properties[key] = val
}