-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
util.go
57 lines (49 loc) · 1.05 KB
/
util.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
49
50
51
52
53
54
55
56
57
package psql
import (
"bytes"
"strconv"
)
func (c *compilerContext) alias(alias string) {
c.w.WriteString(` AS `)
c.quoted(alias)
}
func aliasWithID(w *bytes.Buffer, alias string, id int32) {
w.WriteString(` AS `)
w.WriteString(alias)
w.WriteString(`_`)
int32String(w, id)
}
func colWithTableID(w *bytes.Buffer, table string, id int32, col string) {
w.WriteString(table)
if id >= 0 {
w.WriteString(`_`)
int32String(w, id)
}
w.WriteString(`.`)
w.WriteString(col)
}
func (c *compilerContext) colWithTable(table, col string) {
c.quoted(table)
c.w.WriteString(`.`)
c.quoted(col)
}
func (c *compilerContext) quoted(identifier string) {
switch c.ct {
case "mysql":
c.w.WriteByte('`')
c.w.WriteString(identifier)
c.w.WriteByte('`')
default:
c.w.WriteByte('"')
c.w.WriteString(identifier)
c.w.WriteByte('"')
}
}
func (c *compilerContext) squoted(identifier string) {
c.w.WriteByte('\'')
c.w.WriteString(identifier)
c.w.WriteByte('\'')
}
func int32String(w *bytes.Buffer, val int32) {
w.WriteString(strconv.FormatInt(int64(val), 10))
}