-
Notifications
You must be signed in to change notification settings - Fork 1
/
join.go
49 lines (37 loc) · 874 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
42
43
44
45
46
47
48
49
package nqb
import "bytes"
type JoinClause interface {
KeysClauses
As(alias string) KeysClauses
}
type defaultJoinClause struct {
*defaultKeysClauses
}
func newDefaultJoinClause(parent Statement) *defaultJoinClause {
return &defaultJoinClause{newDefaultKeysClauses(parent)}
}
func (c *defaultJoinClause) As(alias string) KeysClauses {
c.setElement(&asElement{alias})
return newDefaultKeysClauses(c)
}
type joinType string
const (
defaultJoin joinType = ""
inner joinType = "INNER"
left joinType = "LEFT"
leftOuter joinType = "LEFT OUTER"
)
type joinElement struct {
joinType joinType
from string
}
func (e *joinElement) export() string {
buf := bytes.Buffer{}
if e.joinType != defaultJoin {
buf.WriteString(string(e.joinType))
buf.WriteString(" ")
}
buf.WriteString("JOIN ")
buf.WriteString(e.from)
return buf.String()
}