-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_column_index.go
47 lines (40 loc) · 1.04 KB
/
table_column_index.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
package gosql
import "strings"
// ( column_name [, ... ] ) index_parameters |
type columnIndexParameters struct {
// columns
columns expression
// index parameter
indexParameters indexParameters
}
// Columns get columns
func (i *columnIndexParameters) Columns() *expression {
return &i.columns
}
// Column set columns
func (i *columnIndexParameters) Column(col ...string) *columnIndexParameters {
i.columns.Add(col...)
return i
}
// IndexParameters get index parameters
func (i *columnIndexParameters) IndexParameters() *indexParameters {
return &i.indexParameters
}
// String render index parameters
func (i *columnIndexParameters) String() string {
if i.IsEmpty() {
return ""
}
b := strings.Builder{}
if i.columns.Len() > 0 {
b.WriteString("(" + i.columns.String(", ") + ")")
}
if !i.indexParameters.IsEmpty() {
b.WriteString(i.indexParameters.String())
}
return b.String()
}
// IsEmpty is index parameter empty
func (i *columnIndexParameters) IsEmpty() bool {
return i == nil || (i.columns.Len() == 0 && i.indexParameters.IsEmpty())
}