-
Notifications
You must be signed in to change notification settings - Fork 0
/
relationship.go
99 lines (83 loc) · 1.69 KB
/
relationship.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
97
98
99
package talon
import (
bolt "github.com/johnnadratowski/golang-neo4j-bolt-driver/structures/graph"
"github.com/bbuck/talon/types"
)
type Relationship struct {
ID int64
StartNodeID int64
EndNodeID int64
Name string
Properties types.Properties
}
func wrapBoltRelationship(r bolt.Relationship) *Relationship {
return &Relationship{
ID: r.RelIdentity,
StartNodeID: r.StartNodeIdentity,
EndNodeID: r.EndNodeIdentity,
Name: r.Type,
Properties: types.Properties(r.Properties),
}
}
func (*Relationship) Type() EntityType {
return EntityRelationship
}
func (r *Relationship) Get(key string) (val interface{}, ok bool) {
val, ok = r.Properties[key]
return
}
func (r *Relationship) GetString(key string) (string, bool) {
val, ok := r.Get(key)
if ok {
switch str := val.(type) {
case string:
return str, ok
case *string:
return *str, ok
}
}
return "", ok
}
func (r *Relationship) GetInt(key string) (int64, bool) {
val, ok := r.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 (r *Relationship) GetFloat(key string) (float64, bool) {
val, ok := r.Get(key)
if ok {
switch f := val.(type) {
case float32:
return float64(f), ok
case float64:
return f, ok
}
}
return 0, ok
}
func (r *Relationship) GetBool(key string) (bool, bool) {
val, ok := r.Get(key)
if ok {
switch b := val.(type) {
case bool:
return b, ok
}
}
return false, ok
}
func (r *Relationship) Set(key string, val interface{}) {
r.Properties[key] = val
}