-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_exclude_element.go
75 lines (66 loc) · 1.59 KB
/
table_exclude_element.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
package gosql
import "strings"
// exclude element
// { column_name | ( expression ) } [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ]
type excludeElement struct {
// column name
column string
// expression
expression expression
// operator class
opclass string
// direction
direction string
// nulls expression
nulls *string
}
// Column set column name
func (e *excludeElement) Column(column string) *excludeElement {
e.column = column
return e
}
// OpClass set opclass
func (e *excludeElement) OpClass(opclass string) *excludeElement {
e.opclass = opclass
return e
}
// Direction set direction
func (e *excludeElement) Direction(direction string) *excludeElement {
e.direction = direction
return e
}
// Nulls set nulls
func (e *excludeElement) Nulls(nulls *string) *excludeElement {
e.nulls = nulls
return e
}
// Expression get expression
func (e *excludeElement) Expression() *expression {
return &e.expression
}
// String render exclude element
func (e *excludeElement) String() string {
if e.IsEmpty() {
return ""
}
b := strings.Builder{}
if e.column != "" {
b.WriteString(e.column)
} else if e.expression.Len() > 0 {
b.WriteString("(" + e.expression.String(", ") + ")")
}
if e.opclass != "" {
b.WriteString(" " + e.opclass)
}
if e.direction != "" {
b.WriteString(" " + e.direction)
}
if e.nulls != nil {
b.WriteString(" NULLS " + *e.nulls)
}
return b.String()
}
// IsEmpty is exclude element is empty
func (e *excludeElement) IsEmpty() bool {
return e == nil || (e.column == "" && e.expression.Len() == 0 && e.opclass == "" && e.direction == "" && e.nulls == nil)
}