소스 검색

代码优化

thm 8 년 전
부모
커밋
f0e28f96a7
1개의 변경된 파일12개의 추가작업 그리고 8개의 파일을 삭제
  1. 12 8
      app.js

+ 12 - 8
app.js

@@ -16,7 +16,7 @@ server.use(restify.queryParser());
 server.use(restify.bodyParser());
 
 server.post('/api/sqls', function (req, res) {
-    var promises = [];
+    //var promises = [];
 
     if (Array.isArray(req.body)) {
         var sqls = req.body;
@@ -28,26 +28,30 @@ server.post('/api/sqls', function (req, res) {
             function (whilecb) {
                 var tmp = sqls.length > 100 ? sqls.splice(0, 100) : sqls.splice(0, sqls.length);
                 // 执行批量sql文
-                promises.push(tableProvider.excute(tmp.join('')));
-                whilecb();
+                tableProvider.excute(tmp.join('')).then(function () {
+                    whilecb();
+                });
             },
             function (err) {
-
+                if (err == null)
+                    res.send('success');
+                else
+                    res.send('failure');
             });
 
         /*while (sqls.length > 0) {
-            var temp= sqls.length > 100 ? sqls.splice(0,100) : sqls.splice(0, sqls.length);
+            var tmp= sqls.length > 100 ? sqls.splice(0,100) : sqls.splice(0, sqls.length);
             // 执行批量sql文
-            promises.push(tableProvider.excute(temp.join('')));
+            promises.push(tableProvider.excute(tmp.join('')));
         }*/
     }
 
-    Promise.all(promises).then(function () {
+    /*Promise.all(promises).then(function () {
         res.send('success');
     }).catch(function (err) {
         res.send('failure');
         console.log('error:' + err);
-    });
+    });*/
 
     // res.send('ok');
 });