-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
truncate.go
37 lines (29 loc) · 951 Bytes
/
truncate.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
package bob
import (
"errors"
"github.com/lann/builder"
)
type TruncateBuilder builder.Builder
type truncateData struct {
TableName string
}
func init() {
builder.Register(TruncateBuilder{}, truncateData{})
}
// Truncate sets which table to be dropped
func (b TruncateBuilder) truncate(name string) TruncateBuilder {
return builder.Set(b, "TableName", name).(TruncateBuilder)
}
// ToSql returns 3 variables filled out with the correct values based on bindings, etc.
func (b TruncateBuilder) ToSql() (string, []interface{}, error) {
data := builder.GetStruct(b).(truncateData)
return data.ToSql()
}
// ToSql returns 3 variables filled out with the correct values based on bindings, etc.
func (d *truncateData) ToSql() (sqlStr string, args []interface{}, err error) {
if len(d.TableName) == 0 || d.TableName == "" {
err = errors.New("truncate statement must specify a table")
}
sqlStr = "TRUNCATE \"" + d.TableName + "\";"
return
}