builder_join.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2019 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package builder
  5. // InnerJoin sets inner join
  6. func (b *Builder) InnerJoin(joinTable, joinCond interface{}) *Builder {
  7. return b.Join("INNER", joinTable, joinCond)
  8. }
  9. // LeftJoin sets left join SQL
  10. func (b *Builder) LeftJoin(joinTable, joinCond interface{}) *Builder {
  11. return b.Join("LEFT", joinTable, joinCond)
  12. }
  13. // RightJoin sets right join SQL
  14. func (b *Builder) RightJoin(joinTable, joinCond interface{}) *Builder {
  15. return b.Join("RIGHT", joinTable, joinCond)
  16. }
  17. // CrossJoin sets cross join SQL
  18. func (b *Builder) CrossJoin(joinTable, joinCond interface{}) *Builder {
  19. return b.Join("CROSS", joinTable, joinCond)
  20. }
  21. // FullJoin sets full join SQL
  22. func (b *Builder) FullJoin(joinTable, joinCond interface{}) *Builder {
  23. return b.Join("FULL", joinTable, joinCond)
  24. }
  25. // Join sets join table and conditions
  26. func (b *Builder) Join(joinType string, joinTable, joinCond interface{}) *Builder {
  27. switch joinCond.(type) {
  28. case Cond:
  29. b.joins = append(b.joins, join{joinType, joinTable, joinCond.(Cond)})
  30. case string:
  31. b.joins = append(b.joins, join{joinType, joinTable, Expr(joinCond.(string))})
  32. }
  33. return b
  34. }