diff --git a/db.go b/db.go index 86ba4c9d5784dde6afbecbe962e1825bf6fba347..2ba9df76507811017ad1553623eca66ec2b76ecd 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 5da13a16d7401fc9f337d800855c642e6a8d380e..c619ec5d01db0bdaf197345597775b05d16f3fee 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)