-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_tbjoin.go
53 lines (44 loc) · 2.01 KB
/
table_tbjoin.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
package gormcnm
import (
"strings"
"gorm.io/gorm/clause"
)
// LEFTJOIN creates a left join operation for the specified table.
// LEFTJOIN 给指定表创建一个左连接操作。
func (common *ColumnOperationClass) LEFTJOIN(tableName string) *TableJoin {
return newTableJoin(tableName, clause.LeftJoin)
}
// RIGHTJOIN creates a right join operation for the specified table.
// RIGHTJOIN 给指定表创建一个右连接操作。
func (common *ColumnOperationClass) RIGHTJOIN(tableName string) *TableJoin {
return newTableJoin(tableName, clause.RightJoin)
}
// INNERJOIN creates an inner join operation for the specified table.
// INNERJOIN 给指定表创建一个内连接操作。
func (common *ColumnOperationClass) INNERJOIN(tableName string) *TableJoin {
return newTableJoin(tableName, clause.InnerJoin)
}
// CROSSJOIN creates a cross join operation for the specified table.
// CROSSJOIN 给指定表创建一个交叉连接操作。
func (common *ColumnOperationClass) CROSSJOIN(tableName string) *TableJoin {
return newTableJoin(tableName, clause.CrossJoin)
}
// TableJoin represents a join operation on a table, including its type and name.
// TableJoin 表示表上的连接操作,包括连接类型和表名。
type TableJoin struct {
whichJoin clause.JoinType // Type of join (e.g., LEFT, RIGHT, INNER, CROSS)
tableName string // Name of the table involved in the join
}
// newTableJoin creates a new TableJoin instance with the specified table name and join type.
// newTableJoin 使用指定的表名和连接类型创建一个新的 TableJoin 实例。
func newTableJoin(tableName string, whichJoin clause.JoinType) *TableJoin {
return &TableJoin{
whichJoin: whichJoin,
tableName: tableName,
}
}
// On generates the SQL ON clause for the join, combining multiple statements with "AND".
// On 给连接生成 SQL 的 ON 子句,将多个语句用 "AND" 组合。
func (op *TableJoin) On(stmts ...string) string {
return string(op.whichJoin) + " JOIN " + op.tableName + " ON " + strings.Join(stmts, " AND ")
}