github.com/systematiccaos/gorm@v1.22.6/clause/joins.go (about) 1 package clause 2 3 type JoinType string 4 5 const ( 6 CrossJoin JoinType = "CROSS" 7 InnerJoin JoinType = "INNER" 8 LeftJoin JoinType = "LEFT" 9 RightJoin JoinType = "RIGHT" 10 ) 11 12 // Join join clause for from 13 type Join struct { 14 Type JoinType 15 Table Table 16 ON Where 17 Using []string 18 Expression Expression 19 } 20 21 func (join Join) Build(builder Builder) { 22 if join.Expression != nil { 23 join.Expression.Build(builder) 24 } else { 25 if join.Type != "" { 26 builder.WriteString(string(join.Type)) 27 builder.WriteByte(' ') 28 } 29 30 builder.WriteString("JOIN ") 31 builder.WriteQuoted(join.Table) 32 33 if len(join.ON.Exprs) > 0 { 34 builder.WriteString(" ON ") 35 join.ON.Build(builder) 36 } else if len(join.Using) > 0 { 37 builder.WriteString(" USING (") 38 for idx, c := range join.Using { 39 if idx > 0 { 40 builder.WriteByte(',') 41 } 42 builder.WriteQuoted(c) 43 } 44 builder.WriteByte(')') 45 } 46 } 47 }