-
Notifications
You must be signed in to change notification settings - Fork 3
/
drop_index.go
48 lines (40 loc) · 1.02 KB
/
drop_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
48
package sqlbuilder
import (
"bytes"
)
//
// Author: 陈永佳 [email protected], [email protected]
//
type DropIndexBuilder struct {
ctx *SQLContext
name string
table string
}
func newDropIndexBuilder(ctx *SQLContext, indexName string) *DropIndexBuilder {
return &DropIndexBuilder{
ctx: ctx,
name: indexName,
}
}
func (slf *DropIndexBuilder) OnTable(table string) *DropIndexBuilder {
slf.table = table
return slf
}
func (slf *DropIndexBuilder) compile() *bytes.Buffer {
if "" == slf.table {
panic("table not found, you should call 'OnTable(table)' method to set it")
}
//ALTER TABLE table_name DROP INDEX index_name
buf := new(bytes.Buffer)
buf.WriteString("ALTER TABLE ")
buf.WriteString(slf.ctx.escapeName(slf.table))
buf.WriteString(" DROP INDEX ")
buf.WriteString(slf.ctx.escapeName(slf.name))
return buf
}
func (slf *DropIndexBuilder) ToSQL() string {
return sqlEndpoint(slf.compile())
}
func (slf *DropIndexBuilder) Execute() *Executor {
return newExecute(slf.ToSQL(), slf.ctx.prepare)
}