-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedge.go
76 lines (66 loc) · 1.3 KB
/
edge.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
package cypher
import (
"fmt"
)
type Edge struct {
variable string
label Label
properties Properties
path Path
condition Condition
}
func NewEdge() *Edge {
return &Edge{
variable: "",
label: Label{},
properties: Properties{},
path: "",
}
}
func (e *Edge) SetVariable(variable string) *Edge {
e.variable = variable
return e
}
func (e *Edge) SetLabel(label string) *Edge {
e.label.Names = append(e.label.Names, label)
return e
}
func (e *Edge) SetLabels(condition Condition, labels ...string) *Edge {
e.label.Names = append(e.label.Names, labels...)
e.condition = condition
return e
}
func (e *Edge) SetProps(props ...Property) *Edge {
for _, p := range props {
e.properties[p.Key] = p.Value
}
return e
}
func (e *Edge) SetPath(path Path) *Edge {
e.path = path
return e
}
func (e Edge) AsPattern() QueryPattern {
return QueryPattern{Edges: EdgePattern{Edge: &e}}
}
func (e Edge) ToCypher() string {
edge := ""
if e.variable != "" {
edge += e.variable
}
edge += e.label.ToCypher()
if len(e.properties) > 0 {
edge += fmt.Sprintf(" %s", e.properties.ToCypher())
}
edge = fmt.Sprintf("-[%v]-", edge)
switch e.path {
case Outgoing:
edge += ">"
case Incoming:
edge = "<" + edge
case Bidirectional:
edge = "<" + edge + ">"
case Plain:
}
return edge
}