forked from gocraft/dbr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoin.go
41 lines (38 loc) · 754 Bytes
/
join.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 dbr
type JoinType uint8
const (
Inner JoinType = iota
Left
Right
Full
)
func Join(t JoinType, table interface{}, on interface{}) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
buf.WriteString(" ")
switch t {
case Left:
buf.WriteString("LEFT ")
case Right:
buf.WriteString("RIGHT ")
case Full:
buf.WriteString("FULL ")
}
buf.WriteString("JOIN ")
switch table := table.(type) {
case string:
buf.WriteString(d.QuoteIdent(table))
default:
buf.WriteString(d.Placeholder())
buf.WriteValue(table)
}
buf.WriteString(" ON ")
switch on := on.(type) {
case string:
buf.WriteString(on)
case Condition:
buf.WriteString(d.Placeholder())
buf.WriteValue(on)
}
return nil
})
}