From b7056bf561587ba8d1982b74da65c07147c7727e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Nieto?= <jose.carlos@menteslibres.net>
Date: Thu, 1 Oct 2015 07:20:46 +0200
Subject: [PATCH] Removing Join methods from result interface.

---
 db.go                         | 11 -----
 util/sqlutil/result/result.go | 83 -----------------------------------
 2 files changed, 94 deletions(-)

diff --git a/db.go b/db.go
index 86ba4c9d..2ba9df76 100644
--- a/db.go
+++ b/db.go
@@ -285,17 +285,6 @@ type Result interface {
 	// Where() discards the initial filtering conditions and sets new ones.
 	Where(...interface{}) Result
 
-	Join(...interface{}) Result
-
-	LeftJoin(...interface{}) Result
-	RightJoin(...interface{}) Result
-	FullJoin(...interface{}) Result
-	CrossJoin(...interface{}) Result
-
-	On(...interface{}) Result
-
-	Using(...interface{}) Result
-
 	// Group() is used to group results that have the same value in the same
 	// column or columns.
 	Group(...interface{}) Result
diff --git a/util/sqlutil/result/result.go b/util/sqlutil/result/result.go
index 5da13a16..c619ec5d 100644
--- a/util/sqlutil/result/result.go
+++ b/util/sqlutil/result/result.go
@@ -22,13 +22,11 @@
 package result
 
 import (
-	"errors"
 	"fmt"
 	"strings"
 
 	"github.com/jmoiron/sqlx"
 	"upper.io/db"
-	"upper.io/db/util/adapter"
 	"upper.io/db/util/sqlgen"
 	"upper.io/db/util/sqlutil"
 )
@@ -48,7 +46,6 @@ type Result struct {
 	offset    sqlgen.Offset
 	columns   sqlgen.Columns
 	where     sqlgen.Where
-	joins     []*sqlgen.Join
 	orderBy   sqlgen.OrderBy
 	groupBy   sqlgen.GroupBy
 	arguments []interface{}
@@ -77,7 +74,6 @@ func (r *Result) setCursor() error {
 			Columns: &r.columns,
 			Limit:   r.limit,
 			Offset:  r.offset,
-			Joins:   sqlgen.JoinConditions(r.joins...),
 			Where:   &r.where,
 			OrderBy: &r.orderBy,
 			GroupBy: &r.groupBy,
@@ -95,85 +91,6 @@ func (r *Result) Where(terms ...interface{}) db.Result {
 	return r
 }
 
-func (r *Result) pushJoin(t string, tables []interface{}) db.Result {
-	if r.joins == nil {
-		r.joins = []*sqlgen.Join{}
-	}
-
-	tableNames := make([]string, len(tables))
-	for i := range tables {
-		tableNames[i] = fmt.Sprintf("%s", tables[i])
-	}
-
-	r.joins = append(r.joins,
-		&sqlgen.Join{
-			Type:  t,
-			Table: sqlgen.TableWithName(strings.Join(tableNames, ", ")),
-		},
-	)
-
-	return r
-}
-
-func (r *Result) Using(columns ...interface{}) db.Result {
-	if len(r.joins) == 0 {
-		return &adapter.NonExistentResult{errors.New(`Cannot use Using() without a preceding Join() expression.`)}
-	}
-
-	lastJoin := r.joins[len(r.joins)-1]
-
-	if lastJoin.On != nil {
-		return &adapter.NonExistentResult{errors.New(`Cannot use Using() and On() with the same Join() expression.`)}
-	}
-
-	fragments := make([]sqlgen.Fragment, len(columns))
-	for i := range fragments {
-		fragments[i] = sqlgen.ColumnWithName(fmt.Sprintf("%s", columns[i]))
-	}
-
-	lastJoin.Using = sqlgen.UsingColumns(fragments...)
-	return r
-}
-
-func (r *Result) FullJoin(tables ...interface{}) db.Result {
-	return r.pushJoin("CROSS", tables)
-}
-
-func (r *Result) CrossJoin(tables ...interface{}) db.Result {
-	return r.pushJoin("CROSS", tables)
-}
-
-func (r *Result) RightJoin(tables ...interface{}) db.Result {
-	return r.pushJoin("RIGHT", tables)
-}
-
-func (r *Result) LeftJoin(tables ...interface{}) db.Result {
-	return r.pushJoin("LEFT", tables)
-}
-
-func (r *Result) Join(tables ...interface{}) db.Result {
-	return r.pushJoin("", tables)
-}
-
-func (r *Result) On(terms ...interface{}) db.Result {
-	if len(r.joins) == 0 {
-		return &adapter.NonExistentResult{errors.New(`Cannot use On() without a preceding Join() expression.`)}
-	}
-
-	lastJoin := r.joins[len(r.joins)-1]
-
-	if lastJoin.On != nil {
-		return &adapter.NonExistentResult{errors.New(`Cannot use Using() and On() with the same Join() expression.`)}
-	}
-
-	w, a := r.template.ToWhereWithArguments(terms)
-	o := sqlgen.On(w)
-	lastJoin.On = &o
-
-	r.arguments = append(r.arguments, a...)
-	return r
-}
-
 // Determines the maximum limit of results to be returned.
 func (r *Result) Limit(n uint) db.Result {
 	r.limit = sqlgen.Limit(n)
-- 
GitLab