<commit_before>'use strict';

var _ = require('lodash');
var Mixin = require('../../util/mixin');
var Condition = require('../../condition'), w = Condition.w;

/**
 * Check if an argument is a join type.
 *
 * @function Join~isType
 * @private
 * @param {?} arg The argument to check.
 * @return {Boolean}
 */
var isType = function(str) {
  var types = ['inner', 'left', 'right', 'full'];
  return types.indexOf(str) !== -1;
};


/**
 * Join support for queries.
 *
 * @mixin Join
 */
module.exports = Mixin.create(/** @lends Join# */ {
  init: function() {
    this._super();
    this._joins = [];
  },

  /**
   * Duplication implementation.
   *
   * @method
   * @protected
   * @see {@link BaseQuery#_take}
   */
  _take: function(orig) {
    this._super(orig);
    this._joins = orig._joins.slice(0);
  },

  /**
   * Specify a join for a query.
   *
   *     select('cities', ['cities.name', 'countries.name'])
   *       .join('countries', 'cities.country_id=countries.id')
   *     // -> select cities.name, countries.name from cities
   *     // -> inner join countries on cities.country_id = countries.id
   *
   * You can also specify a condition with object syntax to match a field
   * by using the {@link Condition.f} helper. Where clauses can be added as
   * well:
   *
   *     select('cities')
   *       .join('countries', 'left', { 'cities.country_id': f('countries.id') })
   *       .where({ 'cities.name[icontains]': 'city' })
   *     // -> select * from cities
   *     // -> left join countries on cities.country_id = countries.id
   *     // -> where cities.name ilike ?
   *     // !> ['%city%']
   *
   * To make a cross join, you can specify no condition an an inner join will
   * be performed with a `true` condition:
   *
   *     select('cities')
   *       .join('countries')
   *     // -> select * from cities
   *     // -> inner join countries on true
   *
   * @param {String|Object} table The table on which to join. If provided as an
   * object, the key is the table name, and the value is the alias name.
   * @param {String} [type] The join type. This can be one of:
   *   - `'inner'` An inner join (the default)
   *   - `'left'` A left outer join
   *   - `'right'` A right outer join
   *   - `'full'` A full outer join
   * @param {...(Condition|Object|String)} conditions The conditions on which to
   * join. If provided as an object or string, it will be converted to a proper
   * {@link Condition}.
   * @see {@link http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/|A Visual Explanation of SQL Joins}
   * @return {ChainedQuery} The newly configured query.
   */
  join: function(/*table, [alias], [type], ...[condition]*/) {
    var dup = this._dup();
    var args = _.toArray(arguments);

    var alias;
    var table = args.shift();
    var type = isType(args[0]) ? args.shift() : 'inner';
    var condition = args.length > 0 ? w.apply(null, args) : null;

    if (!_.isString(table)) {
      alias = _.values(table)[0];
      table = _.keys(table)[0];
    }<commit_msg>Fixed a comment indicating wrong argument types.<commit_after>'use strict';

var _ = require('lodash');
var Mixin = require('../../util/mixin');
var Condition = require('../../condition'), w = Condition.w;

/**
 * Check if an argument is a join type.
 *
 * @function Join~isType
 * @private
 * @param {?} arg The argument to check.
 * @return {Boolean}
 */
var isType = function(str) {
  var types = ['inner', 'left', 'right', 'full'];
  return types.indexOf(str) !== -1;
};


/**
 * Join support for queries.
 *
 * @mixin Join
 */
module.exports = Mixin.create(/** @lends Join# */ {
  init: function() {
    this._super();
    this._joins = [];
  },

  /**
   * Duplication implementation.
   *
   * @method
   * @protected
   * @see {@link BaseQuery#_take}
   */
  _take: function(orig) {
    this._super(orig);
    this._joins = orig._joins.slice(0);
  },

  /**
   * Specify a join for a query.
   *
   *     select('cities', ['cities.name', 'countries.name'])
   *       .join('countries', 'cities.country_id=countries.id')
   *     // -> select cities.name, countries.name from cities
   *     // -> inner join countries on cities.country_id = countries.id
   *
   * You can also specify a condition with object syntax to match a field
   * by using the {@link Condition.f} helper. Where clauses can be added as
   * well:
   *
   *     select('cities')
   *       .join('countries', 'left', { 'cities.country_id': f('countries.id') })
   *       .where({ 'cities.name[icontains]': 'city' })
   *     // -> select * from cities
   *     // -> left join countries on cities.country_id = countries.id
   *     // -> where cities.name ilike ?
   *     // !> ['%city%']
   *
   * To make a cross join, you can specify no condition an an inner join will
   * be performed with a `true` condition:
   *
   *     select('cities')
   *       .join('countries')
   *     // -> select * from cities
   *     // -> inner join countries on true
   *
   * @param {String|Object} table The table on which to join. If provided as an
   * object, the key is the table name, and the value is the alias name.
   * @param {String} [type] The join type. This can be one of:
   *   - `'inner'` An inner join (the default)
   *   - `'left'` A left outer join
   *   - `'right'` A right outer join
   *   - `'full'` A full outer join
   * @param {...(Condition|Object|String)} conditions The conditions on which to
   * join. If provided as an object or string, it will be converted to a proper
   * {@link Condition}.
   * @see {@link http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/|A Visual Explanation of SQL Joins}
   * @return {ChainedQuery} The newly configured query.
   */
  join: function(/*table, [type], ...[condition]*/) {
    var dup = this._dup();
    var args = _.toArray(arguments);

    var alias;
    var table = args.shift();
    var type = isType(args[0]) ? args.shift() : 'inner';
    var condition = args.length > 0 ? w.apply(null, args) : null;

    if (!_.isString(table)) {
      alias = _.values(table)[0];
      table = _.keys(table)[0];
    }
{'fraction_non_alphanumeric': 0.1619764397905759, 'fraction_numerical': 0.001963350785340314, 'mean_word_length': 2.5561372891215823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7625592', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1962, 'n_words': 607}