-
Notifications
You must be signed in to change notification settings - Fork 7
/
drop.go
41 lines (36 loc) · 920 Bytes
/
drop.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
package sqlbuilder
// DeleteTableStatement represents a "DROP TABLE" statement.
type DropTableStatement struct {
table Table
err error
}
// DropTable returns new "DROP TABLE" statement. The table is Table object to drop.
func DropTable(tbl Table) *DropTableStatement {
if tbl == nil {
return &DropTableStatement{
err: newError("table is nil."),
}
}
if _, ok := tbl.(*table); !ok {
return &DropTableStatement{
err: newError("table is not natural table."),
}
}
return &DropTableStatement{
table: tbl,
}
}
// ToSql generates query string, placeholder arguments, and returns err on errors.
func (b *DropTableStatement) ToSql() (query string, args []interface{}, err error) {
bldr := newBuilder()
defer func() {
query, args, err = bldr.Query(), bldr.Args(), bldr.Err()
}()
if b.err != nil {
bldr.SetError(b.err)
return
}
bldr.Append("DROP TABLE ")
bldr.AppendItem(b.table)
return
}