forked from manhcuongbk56/cypher-go-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.go
90 lines (77 loc) · 1.85 KB
/
merge.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
package cypher
type merge struct {
pattern Pattern
onCreateOrMatchEvents []Visitable
key string
notNil bool
err error
}
var BLANK = RawStringLiteralCreate(" ")
func mergeCreate(pattern Pattern) merge {
if pattern.GetError() != nil {
return mergeError(pattern.GetError())
}
m := merge{
pattern: pattern,
onCreateOrMatchEvents: make([]Visitable, 0),
notNil: true,
}
m.key = getAddress(&m)
return m
}
func mergeCreate1(pattern Pattern, mergeActions []MergeAction) merge {
if pattern.GetError() != nil {
return mergeError(pattern.GetError())
}
for _, action := range mergeActions {
if action.GetError() != nil {
return mergeError(action.GetError())
}
}
onCreateOrMatchEvents := make([]Visitable, 0)
onCreateOrMatchEvents = append(onCreateOrMatchEvents, BLANK)
for _, mergeAction := range mergeActions {
onCreateOrMatchEvents = append(onCreateOrMatchEvents, mergeAction)
}
m := merge{
pattern: pattern,
onCreateOrMatchEvents: onCreateOrMatchEvents,
notNil: true,
}
m.key = getAddress(&m)
return m
}
func mergeError(err error) merge {
return merge{err: err}
}
func (m merge) hasEvent() bool {
return len(m.onCreateOrMatchEvents) > 0
}
func (m merge) GetError() error {
return m.err
}
func (m merge) accept(visitor *CypherRenderer) {
visitor.enter(m)
m.pattern.accept(visitor)
for _, event := range m.onCreateOrMatchEvents {
event.accept(visitor)
}
visitor.leave(m)
}
func (m merge) enter(renderer *CypherRenderer) {
renderer.append("MERGE ")
}
func (m merge) leave(renderer *CypherRenderer) {
if !m.hasEvent() {
renderer.append(" ")
}
}
func (m merge) getKey() string {
return m.key
}
func (m merge) isNotNil() bool {
return m.notNil
}
func (m merge) isUpdatingClause() bool {
panic("implement me")
}