How to use the fxjs.each 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
        each(([i, t]) => go(
          options[i],
          last,
          _ => Object.assign(_, t)
        ))
      );
github marpple / FxSQL / src / index.js View on Github external
                  _ => me.hook && each(left => go(me.hook(left._[me.as]), right => left._[me.as] = right), lefts));
              }));
github marpple / FxSQL / src / index.js View on Github external
                  folded => each(function(left) {
                    left._ = left._ || {};
                    left._[me.as] = folded[left[me.left_key]] || default_value();
                  }, lefts),
                  _ => recur([rights, me]),
github marpple / FxSQL / src / ljoin.js View on Github external
return async function ljoin(strs, ...tails) {
      return go(
        ready_sqls(strs, tails),
        cat,
        filter(t => t.as),
        each(option => {
          option.query = option.query || tag();
          option.table = option.table || (option.rel_type == '-' ? option.as + 's' : option.as);
          option.column = option.column || CL(...table_columns[option.table]);
          option.left_joins = [];
          option.rels = [];
          option.row_number = option.row_number || [];
        }),
        ([left, ...rest]) => {
          const cur = [left];
          each(me => {
            while (!(last(cur).depth < me.depth)) cur.pop();
            const left = last(cur);
            if (me.rel_type == '-') {
              me.left_key = me.left_key || (me.is_poly ? 'id' : singular(me.table) + '_id');
              me.key = me.key || (me.is_poly ? 'attached_id' : 'id');
              left.left_joins.push(me);
github marpple / FxSQL / src / index.js View on Github external
function setting([left, ...rest]) {
          const cur = [left];
          each(me => {
            while (!(last(cur).depth < me.depth)) cur.pop();
            const left = last(cur);
            left.rels.push(me);
            if (me.rel_type == '-') {
              me.left_key = me.left_key || (me.is_poly ? 'id' : singular(me.table) + '_id');
              me.where_key = me.key || (me.is_poly ? 'attached_id' : 'id');
              me.xjoin = tag();
            } else if (me.rel_type == '<') {
              me.left_key = me.left_key || 'id';
              me.where_key = me.key || (me.is_poly ? 'attached_id' : singular(left.table) + '_id');
              me.xjoin = tag();
            } else if (me.rel_type == 'x') {
              me.left_key = me.left_key || 'id';
              me.where_key = '_#_xtable_#_.' + (me.left_xkey || singular(left.table) + '_id');
              var xtable = me.xtable || (left.table + '_' + me.table);
              me.xjoin = SQL `INNER JOIN ${TB(xtable)} AS ${TB('_#_xtable_#_')} on ${EQ({
github marpple / FxSQL / src / index.js View on Github external
return async function(strs, ...tails) {
      return go(
        ready_sqls(strs, tails),
        deep_flat,
        filter(t => t.as),
        each(option => {
          option.column = option.column || '*';
          option.query = option.query || tag();
          option.table = option.table || (option.rel_type == '-' ? plural(option.as) : option.as);
          option.rels = [];
          option.row_number = option.row_number || [];
        }),
        function setting([left, ...rest]) {
          const cur = [left];
          each(me => {
            while (!(last(cur).depth < me.depth)) cur.pop();
            const left = last(cur);
            left.rels.push(me);
            if (me.rel_type == '-') {
              me.left_key = me.left_key || (me.is_poly ? 'id' : singular(me.table) + '_id');
              me.where_key = me.key || (me.is_poly ? 'attached_id' : 'id');
              me.xjoin = tag();
github marpple / FxSQL / src / ljoin.js View on Github external
function recur(me) {
        me.left_join_over = true;
        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}>_
github marpple / FxSQL / src / ljoin.js View on Github external
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))]);
                }
              );
github marpple / FxSQL / src / ljoin.js View on Github external
([left, ...rest]) => {
          const cur = [left];
          each(me => {
            while (!(last(cur).depth < me.depth)) cur.pop();
            const left = last(cur);
            if (me.rel_type == '-') {
              me.left_key = me.left_key || (me.is_poly ? 'id' : singular(me.table) + '_id');
              me.key = me.key || (me.is_poly ? 'attached_id' : 'id');
              left.left_joins.push(me);
            } else {
              me.left_key = me.left_key || 'id';
              me.key = me.key || (me.is_poly ? 'attached_id' : singular(left.table) + '_id');
            }
            left.rels.push(me);

            me.poly_type = me.is_poly ?
              SQL `AND ${EQ(
                is_string(me.poly_type) ? { attached_type: me.poly_type || left.table } : me.poly_type
              )}` : tag();
github marpple / FxSQL / src / ljoin.js View on Github external
!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];