-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (47 loc) · 1.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var mysql=require("mysql");
var async=require("async");
module.exports = function (container) {
var tasks = [];
tasks.push({
name: "mysqlQuery",
def: function (instacne,config,query) {
return {
config:config,
query:query
}
},
exec: function (scope, next) {
var connection = mysql.createConnection(scope.config);
var query=scope.query;
if (query==null)
query=scope.$$input;
var result=[];
async.series([
function(cb){
connection.connect();
cb();
},
function(cb){
connection.query(query,function(err,rows,field){
if (err) {
throw err;
}
for(var i=0;i<rows.length;i++){
result.push(rows[i]);
}
cb();
});
},
function(cb){
connection.end();
cb();
},
function(cb){
next(result);
cb();
}
]);
}
});
return tasks;
}