-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuse.go
55 lines (42 loc) · 1.18 KB
/
use.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
package nqb
import "bytes"
type UseIndexClause interface {
KeysClauses
UseIndexRef(indexes ...*indexReference) KeysClauses
UseIndex(indexes ...string) KeysClauses
}
type defaultUseIndexClause struct {
*defaultKeysClauses
}
func newDefaultUseIndexClause(parent Statement) *defaultUseIndexClause {
return &defaultUseIndexClause{newDefaultKeysClauses(parent)}
}
func (c *defaultUseIndexClause) UseIndexRef(indexes ...*indexReference) KeysClauses {
c.setElement(&useIndexElement{indexes})
return newDefaultKeysClauses(c)
}
func (c *defaultUseIndexClause) UseIndex(indexes ...string) KeysClauses {
var indexRefs []*indexReference
for _, index := range indexes {
indexRef := IndexRef(index)
indexRefs = append(indexRefs, indexRef)
}
return c.UseIndexRef(indexRefs...)
}
type useIndexElement struct {
indexReferences []*indexReference
}
func (e *useIndexElement) export() string {
if e.indexReferences == nil || len(e.indexReferences) < 1 {
return ""
}
buf := bytes.NewBufferString("USE INDEX (")
for i, indexReference := range e.indexReferences {
if i > 0 {
buf.WriteString(",")
}
buf.WriteString(indexReference.String())
}
buf.WriteString(")")
return buf.String()
}