How to use the fxjs.uniq function in fxjs

To help you get started, we’ve selected a few fxjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marpple / FxSQL / src / index.js View on Github external
return lefts.length && option.rels.length && go(option.rels, C.map(async function(me) {
                const query = me.query();
                if (query && query.text) query.text = query.text.replace(/^\s*WHERE/i, 'AND');

                var fold_key = me.rel_type == 'x' ?
                  `_#_${me.where_key.split('.')[1]}_#_` : me.where_key;

                const colums = uniq(add_column(me).originals.concat(
                  me.rel_type != 'x' ? me.as + '.' + me.where_key : me.where_key + ' AS ' + fold_key));

                const in_vals = filter(a => a != null, pluck(me.left_key, lefts));
                const is_row_num = me.row_number.length == 2;
                const rights = (!in_vals.length ? [] : await (is_row_num ?
                  QUERY `
                  SELECT *
                  FROM (
                    SELECT
                      ${COLUMN(...colums)}, 
                      ROW_NUMBER() OVER (PARTITION BY ${CL(me.where_key)} ORDER BY ${me.row_number[1]}) as "--row_number--"
                    FROM ${TB(me.table)} AS ${TB(me.as)} 
                    ${me.xjoin} 
                    WHERE ${IN(me.as +'.'+me.where_key, in_vals)} ${me.poly_type} ${tag(query)}
                  ) AS "--row_number_table--"
                  WHERE "--row_number_table--"."--row_number--"<=${me.row_number[0]}`
github marpple / FxSQL / src / ljoin.js View on Github external
function where_in_query(left, where_in, QUERY) {
    const colums = uniq(add_column(left).originals.concat(left.key));
    const query = left.query();
    if (query && query.text) query.text = query.text.replace(/^\s*WHERE/i, 'AND');
    return left.row_number.length == 2 ?
      QUERY `
      SELECT *
      FROM (
        SELECT
          ${COLUMN(...colums)}, 
          ROW_NUMBER() OVER (PARTITION BY ${CL(left.key)} ORDER BY ${left.row_number[1]}) as "--row_number--"
        FROM ${TB(left.table)} AS ${TB(left.as)}       
        ${where_in || tag()}
      ) AS "--row_number_table--"
      WHERE "--row_number_table--"."--row_number--"<=${left.row_number[0]}`
      :
      QUERY`
      SELECT ${CL(...colums)}
github marpple / FxSQL / src / index.js View on Github external
function BASE_IN(key, operator, values) {
    values = uniq(values);

    var keys_text = COLUMN(...wrap_arr(key))().text;
    return {
      text: `${Array.isArray(key) ? `(${keys_text})` : keys_text} ${operator} (${values.map(
        Array.isArray(key) ? v => `(${v.map(to_q).join(', ')})` : to_q
      ).join(', ')})`,
      values: deep_flat(values)
    };
  }
github marpple / FxSQL / src / ljoin.js View on Github external
each(right => {
          const query = right.query();
          right.lj_as = 'lj'+ i++ + "//"+right.depth;
          if (query && query.text) query.text = query.text.replace(/^\s*WHERE/i, 'AND');
          join_columns.push(
            uniq(add_as_join(right, right.lj_as).originals
              .concat(right.as + '.' + right.key + ' AS ' + `${right.lj_as}>_<${right.key}`)
              .concat(right.as + '.id' + ' AS ' + `${right.lj_as}>_