记录一次node单创建的性能问题批量组装sql一次发送

 DataHp.myBatchCreate = async (sql,values) => {
    return new Promise(function (resolve, reject) {
      DataHp.dataSource.connector.query(sql, function (err, data) {
        if (err) {
          reject(new FunctionError("QUERY_ERROR", "查询数据失败!"));
        }
        resolve(data);
      })
    })
  }
  function FindInsetSql(table,data,values){
    //INSERT INTO xx(1,2,3,4) VALUES (123,2,3,4),(2,3,4,5,6,)
    let str=`INSERT INTO ${table}(`
    let stra="";
    if(data==null){
      data=values[0];
    }
    for(let k in data){
      stra+=k+",";
    }
    stra= stra.substring(0,stra.length-1);
    str+=stra;
    str+=") VALUES ";
    let three="";
    for(let i=0;i<values.length;i++){
      let a="(";

      for(let k in data){
        let aaa=values[i][k];

        if(aaa){
          a+="'"+aaa+"',";
        }else{
          a+=aaa+",";
        }
      }
      a= a.substring(0,a.length-1);
      a+="),";
      three+=a;
    }
    three= three.substring(0,three.length-1);
    str+=three;
    return str;
  }
  DataHp.BatchCreate = async (table,data,values) => {
    if(values&&values.length>0){
      // console.log(values.length+"\t"+table);
      return  await DataHp.myBatchCreate( FindInsetSql(table,data,values));
    }
  }

调用

      await DataHp.BatchCreate("report",reportInputs[0],reportInputs);
上一篇:实现3D 场景——three.js学习篇五之物体贴图


下一篇:移植一个Houdini的动画到WebGL中