src/sequelize/lib/utils/join-sql-fragments.js
/**
 * Joins an array with a single space, auto trimming when needed.
 *
 * Certain elements do not get leading/trailing spaces.
 *
 * @param {any[]} array The array to be joined. Falsy values are skipped. If an
 * element is another array, this function will be called recursively on that array.
 * Otherwise, if a non-string, non-falsy value is present, a TypeError will be thrown.
 *
 * @returns {string} The joined string.
 *
 * @private
 */
Joins an array with a single space, auto trimming when needed.
Certain elements do not get leading/trailing spaces.

@param {any[]} array The array to be joined. Falsy values are skipped. If an
element is another array, this function will be called recursively on that array.
Otherwise, if a non-string, non-falsy value is present, a TypeError will be thrown.

@returns {string} The joined string.

@private
Joins an array with a single space auto trimming when needed . Certain elements do not get leading / trailing spaces . @param { any [] } array The array to be joined . Falsy values are skipped . If an element is another array this function will be called recursively on that array . Otherwise if a non - string non - falsy value is present a TypeError will be thrown . @returns { string } The joined string . @private
function joinSQLFragments(array) {
  if (array.length === 0) return '';
  array = array.filter(x => x);
  array = array.map(fragment => {
    if (Array.isArray(fragment)) {
      return joinSQLFragments(fragment);
    }
    return fragment;
  });
  for (const fragment of array) {
    if (fragment && typeof fragment !== 'string') {
      const error = new TypeError(`Tried to construct a SQL string with a non-string, non-falsy fragment (${fragment}).`);
      error.args = array;
      error.fragment = fragment;
      throw error;
    }
  }
  array = array.map(x => x.trim());
  array = array.filter(x => x !== '');
  let res = singleSpaceJoinHelper(array)
  return res;
}
function joinSQLFragments ( array ) { if ( array . length === 0 ) return '' ; array = array . filter ( x => x ) ; array = array . map ( fragment => { if ( Array . isArray ( fragment ) ) { return joinSQLFragments ( fragment ) ; } return fragment ; } ) ; for ( const fragment of array ) { if ( fragment && typeof fragment !== 'string' ) { const error = new TypeError ( ` ${ fragment } ` ) ; error . args = array ; error . fragment = fragment ; throw error ; } } array = array . map ( x => x . trim ( ) ) ; array = array . filter ( x => x !== '' ) ; let res = singleSpaceJoinHelper ( array ) return res ; }
Joins an array with a single space, auto trimming when needed.
Joins an array with a single space auto trimming when needed .
// Skip falsy fragments // 使用递归的方式处理数组元素 // 确保所有元素都是字符串 // 去掉元素的前后空格 // 去掉空字符串