forked from manhcuongbk56/cypher-go-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alias_expression.go
90 lines (76 loc) · 2.15 KB
/
alias_expression.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
import (
"errors"
)
type AliasedExpression struct {
ExpressionContainer
delegate Expression
alias string
key string
notNil bool
err error
}
func AliasedExpressionCreate(delegate Expression, alias string) AliasedExpression {
if delegate == nil || !delegate.isNotNil() {
return AliasedExpressionError(errors.New("expression to alias can't be nil"))
}
if delegate.GetError() != nil {
return AliasedExpressionError(delegate.GetError())
}
if alias == "" {
return AliasedExpressionError(errors.New("the alias may not be empty"))
}
a := AliasedExpression{
delegate: delegate,
alias: alias,
notNil: true,
}
a.key = getAddress(&a)
a.ExpressionContainer = ExpressionWrap(a)
return a
}
func AliasedExpressionError(err error) AliasedExpression {
return AliasedExpression{
err: err,
}
}
func (aliased AliasedExpression) GetError() error {
return aliased.err
}
func (aliased AliasedExpression) isNotNil() bool {
return aliased.notNil
}
func (aliased AliasedExpression) GetExpressionType() ExpressionType {
return EXPRESSION
}
func (aliased AliasedExpression) Aliased(newAlias string) AliasedExpression {
if newAlias == "" {
return AliasedExpressionError(errors.New("the alias may not be empty"))
}
return AliasedExpressionCreate(aliased.delegate, newAlias)
}
func (aliased AliasedExpression) accept(visitor *CypherRenderer) {
visitor.enter(aliased)
NameOrExpression(aliased.delegate).accept(visitor)
visitor.leave(aliased)
}
func (aliased AliasedExpression) getKey() string {
return aliased.key
}
func (aliased AliasedExpression) enter(renderer *CypherRenderer) {
if _, visited := renderer.visitableToAliased[aliased.delegate.getKey()]; visited {
renderer.append(EscapeIfNecessary(aliased.alias))
}
}
func (aliased AliasedExpression) leave(renderer *CypherRenderer) {
if _, visited := renderer.visitableToAliased[aliased.delegate.getKey()]; !visited {
renderer.append(" AS ")
renderer.append(EscapeIfNecessary(aliased.alias))
}
}
func (aliased AliasedExpression) GetAlias() string {
return aliased.alias
}
func (aliased AliasedExpression) AsName() SymbolicName {
return SymbolicNameCreate(aliased.alias)
}