-
Notifications
You must be signed in to change notification settings - Fork 2
/
drop.go
35 lines (29 loc) · 860 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
package sol
import (
"fmt"
"github.com/aodin/sol/dialect"
)
// DropStmt is the internal representation of an DROP TABLE statement.
type DropStmt struct {
table *TableElem
ifExists bool
}
// IfExists adds the IF EXISTS modifier to a DROP TABLE statement.
func (stmt DropStmt) IfExists() DropStmt {
stmt.ifExists = true
return stmt
}
// String outputs the parameter-less CREATE TABLE statement in a neutral
// dialect.
func (stmt DropStmt) String() string {
c, _ := stmt.Compile(&defaultDialect{}, Params())
return c
}
// Compile outputs the DROP TABLE statement using the given dialect and
// parameters.
func (stmt DropStmt) Compile(d dialect.Dialect, p *Parameters) (string, error) {
if stmt.ifExists {
return fmt.Sprintf(`DROP TABLE IF EXISTS %s`, stmt.table.Name()), nil
}
return fmt.Sprintf(`DROP TABLE %s`, stmt.table.Name()), nil
}