github.com/paweljw/pop@v4.13.1+incompatible/query_joins.go (about)

     1  package pop
     2  
     3  import (
     4  	"github.com/gobuffalo/pop/internal/oncer"
     5  	"github.com/gobuffalo/pop/logging"
     6  )
     7  
     8  // Join will append a JOIN clause to the query
     9  func (q *Query) Join(table string, on string, args ...interface{}) *Query {
    10  	if q.RawSQL.Fragment != "" {
    11  		log(logging.Warn, "Query is setup to use raw SQL")
    12  		return q
    13  	}
    14  	q.joinClauses = append(q.joinClauses, joinClause{"JOIN", table, on, args})
    15  	return q
    16  }
    17  
    18  // LeftJoin will append a LEFT JOIN clause to the query
    19  func (q *Query) LeftJoin(table string, on string, args ...interface{}) *Query {
    20  	if q.RawSQL.Fragment != "" {
    21  		log(logging.Warn, "Query is setup to use raw SQL")
    22  		return q
    23  	}
    24  	q.joinClauses = append(q.joinClauses, joinClause{"LEFT JOIN", table, on, args})
    25  	return q
    26  }
    27  
    28  // RightJoin will append a RIGHT JOIN clause to the query
    29  func (q *Query) RightJoin(table string, on string, args ...interface{}) *Query {
    30  	if q.RawSQL.Fragment != "" {
    31  		log(logging.Warn, "Query is setup to use raw SQL")
    32  		return q
    33  	}
    34  	q.joinClauses = append(q.joinClauses, joinClause{"RIGHT JOIN", table, on, args})
    35  	return q
    36  }
    37  
    38  // LeftOuterJoin will append a LEFT OUTER JOIN clause to the query
    39  func (q *Query) LeftOuterJoin(table string, on string, args ...interface{}) *Query {
    40  	if q.RawSQL.Fragment != "" {
    41  		log(logging.Warn, "Query is setup to use raw SQL")
    42  		return q
    43  	}
    44  	q.joinClauses = append(q.joinClauses, joinClause{"LEFT OUTER JOIN", table, on, args})
    45  	return q
    46  }
    47  
    48  // RightOuterJoin will append a RIGHT OUTER JOIN clause to the query
    49  func (q *Query) RightOuterJoin(table string, on string, args ...interface{}) *Query {
    50  	if q.RawSQL.Fragment != "" {
    51  		log(logging.Warn, "Query is setup to use raw SQL")
    52  		return q
    53  	}
    54  	q.joinClauses = append(q.joinClauses, joinClause{"RIGHT OUTER JOIN", table, on, args})
    55  	return q
    56  }
    57  
    58  // LeftInnerJoin will append an INNER JOIN clause to the query
    59  //
    60  // Deprecated: Use InnerJoin instead
    61  func (q *Query) LeftInnerJoin(table string, on string, args ...interface{}) *Query {
    62  	oncer.Deprecate(0, "pop.Query#LeftInnerJoin", "Use pop.Query#InnerJoin instead.")
    63  	return q.InnerJoin(table, on, args...)
    64  }
    65  
    66  // RightInnerJoin will append an INNER JOIN clause to the query
    67  //
    68  // Deprecated: Use InnerJoin instead
    69  func (q *Query) RightInnerJoin(table string, on string, args ...interface{}) *Query {
    70  	oncer.Deprecate(0, "pop.Query#RightInnerJoin", "Use pop.Query#InnerJoin instead.")
    71  	return q.InnerJoin(table, on, args...)
    72  }
    73  
    74  // InnerJoin will append an INNER JOIN clause to the query
    75  func (q *Query) InnerJoin(table string, on string, args ...interface{}) *Query {
    76  	if q.RawSQL.Fragment != "" {
    77  		log(logging.Warn, "Query is setup to use raw SQL")
    78  		return q
    79  	}
    80  	q.joinClauses = append(q.joinClauses, joinClause{"INNER JOIN", table, on, args})
    81  	return q
    82  }