How to use fxjs - 10 common examples

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
async function(me) {
          const lefts = await QUERY `
            SELECT ${add_column(me)}
              FROM ${TB(me.table)} AS ${TB(me.as)} ${me.query}`;
          return go(
            [lefts, me],
            function recur([lefts, option]) {
              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 `
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 / 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]}`
                  :
                  QUERY `
                  SELECT ${COLUMN(...colums)}
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 / index.js View on Github external
function ASSOCIATE_MODULE(strs, ...tails) {
    strs = strs.slice();
    strs.push(strs.pop() + '\n');
    var [strs2, tails2] = import_module(strs, tails);

    const splited = deep_flat(strs.map(str => str.split('\n')))
      .filter(str => str.match(/^\s*/)[0])
      .filter(str => str.trim());

    const min = min_by(str => str.match(/^\s*/)[0].length, splited);
    const a = '\n' + min.match(/^\s*/)[0];

    return [strs2.map(str => str.split(a).join('\n')), tails2];
  }
github marpple / FxSQL / src / index.js View on Github external
function import_module(strs, tails) {
    if (!tails.some(tail => typeof tail == 'function' && !is_tag(tail))) return [strs, tails];

    var strs2 = [...strs];
    var j = 0;
    var tails2 = tails.map(function(tail, i) {
      if (typeof tail != 'function' || is_tag(tail)) return tail;
      var k = i + j++;
      var spaces = last(strs2[k].split('\n')).match(/^\s*/)[0];
      var [strs3, tails3] = tail();
      strs2.splice(k+1, 0, strs3.map(str => str.replace(/\n/g, '\n' + spaces)));
      return tails3;
    });

    return [
      deep_flat(strs2).filter(str => str.trim()).reduce((strs, str, i) => {
        if (i == 0) return strs.push(str), strs;
        const splited = last(strs).split('\n');
        if (!last(splited).trim()) {
          splited[splited.length-1] = str.substr(1);
          strs[strs.length-1] = splited.join('\n');
        } else {
          strs.push(str);
        }
        return strs;
      }, []),
      deep_flat(tails2)];
  }
github marpple / FxSQL / src / index.js View on Github external
return tails3;
    });

    return [
      deep_flat(strs2).filter(str => str.trim()).reduce((strs, str, i) => {
        if (i == 0) return strs.push(str), strs;
        const splited = last(strs).split('\n');
        if (!last(splited).trim()) {
          splited[splited.length-1] = str.substr(1);
          strs[strs.length-1] = splited.join('\n');
        } else {
          strs.push(str);
        }
        return strs;
      }, []),
      deep_flat(tails2)];
  }
github marpple / FxSQL / src / index.js View on Github external
function recur([lefts, option]) {
              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
github marpple / FxSQL / src / index.js View on Github external
function ASSOCIATE_MODULE(strs, ...tails) {
    strs = strs.slice();
    strs.push(strs.pop() + '\n');
    var [strs2, tails2] = import_module(strs, tails);

    const splited = deep_flat(strs.map(str => str.split('\n')))
      .filter(str => str.match(/^\s*/)[0])
      .filter(str => str.trim());

    const min = min_by(str => str.match(/^\s*/)[0].length, splited);
    const a = '\n' + min.match(/^\s*/)[0];

    return [strs2.map(str => str.split(a).join('\n')), tails2];
  }