forked from chuckpreslar/codex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_sql_visitor.go
More file actions
51 lines (40 loc) · 1.03 KB
/
my_sql_visitor.go
File metadata and controls
51 lines (40 loc) · 1.03 KB
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
package codex
import (
"fmt"
)
const (
MYSQL_QUOTE = '`'
)
type MySqlVisitor struct {
*ToSqlVisitor
}
var _ VisitorInterface = (*MySqlVisitor)(nil)
func NewMySqlVisitor() *MySqlVisitor {
return &MySqlVisitor{NewToSqlVisitor()}
}
func (v *MySqlVisitor) Accept(o interface{}) (string, []interface{}, error) {
err := v.Visit(o, v)
return v.String(), v.Args(), err
}
// Begin Helpers.
func (v *MySqlVisitor) QuoteTableName(o interface{}, visitor VisitorInterface) (err error) {
s, ok := o.(string)
if !ok {
return fmt.Errorf("MySqlVisitor.QuoteTableName() expected string but got %#v", o)
}
visitor.AppendSqlByte(MYSQL_QUOTE)
visitor.AppendSqlStr(s)
visitor.AppendSqlByte(MYSQL_QUOTE)
return
}
func (v *MySqlVisitor) QuoteColumnName(o interface{}, visitor VisitorInterface) (err error) {
s, ok := o.(string)
if !ok {
return fmt.Errorf("MySqlVisitor.QuoteColumnName() expected string but got %#v", o)
}
visitor.AppendSqlByte(MYSQL_QUOTE)
visitor.AppendSqlStr(s)
visitor.AppendSqlByte(MYSQL_QUOTE)
return
}
// End Helpers.