How to use the fxjs.map 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 / ljoin.js View on Github external
${COLUMN(...cat(join_columns))},
            ROW_NUMBER() OVER (PARTITION BY ${CL(left.as + '.' + left.key)} ORDER BY ${left.row_number[1]}) as "--row_number--"
          FROM ${TB(left.table)} AS ${TB(left.as)}
          ${SQLS(join_sqls)}
          ${where_in || tag()}
          ${tag(query)}
        ) AS "--row_number_table--"
        WHERE "--row_number_table--"."--row_number--"<=${left.row_number[0]}`
        :
        QUERY `
          SELECT ${COLUMN(...cat(join_columns))}
          FROM ${TB(left.table)} AS ${TB(left.as)}
          ${SQLS(join_sqls)}
          ${where_in || tag()}
          ${tag(query)}`,
      left.row_number.length == 2 ? map(r => delete r['--row_number--'] && r) : r => r,
      map(row => {
        const before_result_obj = {};
        const result_obj = {};
        for (const as in row) {
          if (as.indexOf('>_<') == -1) return ;
          const split_as = as.split('>_<');
          var tas = split_as[0];
          before_result_obj[tas] = before_result_obj[tas] || { _:{} };
          before_result_obj[tas][split_as[1]] = row[as];
        }
        !function recur(me, memo) {
          memo[me.as] = before_result_obj[me.lj_as];
          each(right => recur(right, memo[me.as]._), me.left_joins);
        }(left, result_obj);
        return result_obj[left.as];
      })
github marpple / FxSQL / src / ljoin.js View on Github external
ROW_NUMBER() OVER (PARTITION BY ${CL(left.as + '.' + left.key)} ORDER BY ${left.row_number[1]}) as "--row_number--"
          FROM ${TB(left.table)} AS ${TB(left.as)}
          ${SQLS(join_sqls)}
          ${where_in || tag()}
          ${tag(query)}
        ) AS "--row_number_table--"
        WHERE "--row_number_table--"."--row_number--"<=${left.row_number[0]}`
        :
        QUERY `
          SELECT ${COLUMN(...cat(join_columns))}
          FROM ${TB(left.table)} AS ${TB(left.as)}
          ${SQLS(join_sqls)}
          ${where_in || tag()}
          ${tag(query)}`,
      left.row_number.length == 2 ? map(r => delete r['--row_number--'] && r) : r => r,
      map(row => {
        const before_result_obj = {};
        const result_obj = {};
        for (const as in row) {
          if (as.indexOf('>_<') == -1) return ;
          const split_as = as.split('>_<');
          var tas = split_as[0];
          before_result_obj[tas] = before_result_obj[tas] || { _:{} };
          before_result_obj[tas][split_as[1]] = row[as];
        }
        !function recur(me, memo) {
          memo[me.as] = before_result_obj[me.lj_as];
          each(right => recur(right, memo[me.as]._), me.left_joins);
        }(left, result_obj);
        return result_obj[left.as];
      })
    )
github marpple / FxSQL / src / ljoin.js View on Github external
cmap(async function(me) {
              const f_key_ids = uniq(filter((r) => !!r, pluck(me.left_key, results)));
              if (me.rel_type == '-' || !f_key_ids.length) return recur([me, cat(map(r => r._ ? r._[me.as] : null, results))]);
              return go(
                (!me.left_join_over && me.left_joins.length ?
                  left_join_query : where_in_query)(me, SQL `WHERE ${IN(me.as + '.' + me.key, f_key_ids)}`, QUERY),
                group_by((v) => v[me.key]),
                function(groups) {
                  each(function(result) {
                    result._ = result._ || {};
                    result._[me.as] = (groups[result[me.left_key]] || []);
                  }, results);
                  return recur([me, cat(map(r => r._ ? r._[me.as] : null, results))]);
                }
              );
            }),
            () => results
github marpple / FxSQL / src / index.js View on Github external
return tag(function () {
      values = Array.isArray(values) ? values : [values];

      const columns = go(
        values,
        map(Object.keys),
        flat,
        uniq);

      const DEFAULTS = go(
        columns,
        map(k => [k, SymbolDefault]),
        object);

      values = values
        .map(v => Object.assign({}, DEFAULTS, v))
        .map(v => Object.values(v));

      return {
        text: `(${COLUMN(...columns)().text}) VALUES (${
          values
            .map(v => v.map(v => v == SymbolDefault ? 'DEFAULT' : to_q()).join(', '))
github marpple / FxSQL / src / ljoin.js View on Github external
const add_as_join = (me, as) =>
    COLUMN(...go(
      me.column.originals.concat(pluck('left_key', me.left_joins)),
      map(c => me.as + '.' + c + ' AS ' + `${as}>_<${c}`),
      uniq
    ));
github marpple / FxSQL / src / index.js View on Github external
rel_type = prefix.trim();
            as = as.substr(1).trim();
            return { depth, as, rel_type }
          } else if (prefix == 'p ') {
            rel_type = as[2];
            as = as.substr(3).trim();
            return { depth, as, rel_type, is_poly: true }
          } else {
            return { depth, as };
          }
        })
      );

      go(
        tails2,
        map(tail =>
          is_tag(tail) ?
            { query: tail } :
            Object.assign({}, tail, { query: tail.query || tag() })
        ),
        Object.entries,
        each(([i, t]) => go(
          options[i],
          last,
          _ => Object.assign(_, t)
        ))
      );

      return options;
  }
github marpple / FxSQL / src / index.js View on Github external
return tag(function () {
      values = Array.isArray(values) ? values : [values];

      const columns = go(
        values,
        map(Object.keys),
        flat,
        uniq);

      const DEFAULTS = go(
        columns,
        map(k => [k, SymbolDefault]),
        object);

      values = values
        .map(v => Object.assign({}, DEFAULTS, v))
        .map(v => Object.values(v));

      return {
        text: `(${COLUMN(...columns)().text}) VALUES (${
          values
            .map(v => v.map(v => v == SymbolDefault ? 'DEFAULT' : to_q()).join(', '))
            .join('), (')})`,
        values: flat(values.map(v => v.filter(v => v != SymbolDefault)))
      }
    });
  }