-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.go
111 lines (94 loc) · 1.65 KB
/
table.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package orm
type TableReference interface {
table()
}
type JoinBuilder struct {
left TableReference
typ string
right TableReference
}
// Table 普通表
type Table struct {
entity any
alias string
}
func TableOf(entity any) Table {
return Table{entity: entity}
}
func (t Table) table() {}
func (t Table) Join(right TableReference) *JoinBuilder {
return &JoinBuilder{
left: t,
right: right,
typ: "JOIN",
}
}
func (t Table) LeftJoin(right TableReference) *JoinBuilder {
return &JoinBuilder{
left: t,
right: right,
typ: "LEFT JOIN",
}
}
func (t Table) RightJoin(right TableReference) *JoinBuilder {
return &JoinBuilder{
left: t,
right: right,
typ: "RIGHT JOIN",
}
}
func (t Table) Col(col string) Column {
return Column{
name: col,
table: t,
}
}
func (t Table) As(alias string) Table {
t.alias = alias
return t
}
type Join struct {
left TableReference
typ string
right TableReference
on []Predicate
using []string
}
func (j Join) table() {}
func (j Join) Join(right TableReference) *JoinBuilder {
return &JoinBuilder{
left: j,
right: right,
typ: "JOIN",
}
}
func (j Join) LeftJoin(right TableReference) *JoinBuilder {
return &JoinBuilder{
left: j,
right: right,
typ: "LEFT JOIN",
}
}
func (j Join) RightJoin(right TableReference) *JoinBuilder {
return &JoinBuilder{
left: j,
right: right,
typ: "RIGHT JOIN",
}
}
func (j *JoinBuilder) On(ps ...Predicate) Join {
return Join{
left: j.left,
typ: j.typ,
right: j.right,
on: ps,
}
}
func (j *JoinBuilder) Using(usg ...string) Join {
return Join{
left: j.left,
right: j.right,
typ: j.typ,
using: usg,
}
}