-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
93 lines (55 loc) · 1.65 KB
/
test.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var suspend = require("suspend"),
resume = suspend.resume;
var MysqlSuspend = require("./mysql-suspend");
MysqlSuspend.config = require('./tests/dbConfig.json');
var db = new MysqlSuspend(resume);
suspend(function*() {
db.throwErrors = false;
yield db.start();
let result = yield db.selectRow("select id,name from test where id=? ;",[2]);
if (result!=null) {
console.log(result.name);
}
yield db.close();
console.log("closed");
yield db.start();
console.log("reopened");
//let arr = yield db.selectArray("select id,name from characters ;");
// console.log(arr);
console.log("------------------------");
yield db.query("select name from characters limit 20 ;");
if (db.error()) {
console.log("error:",db.error);
db.end();
return;
}
console.log(db.rowCount);
console.log(db.rows);
yield db.query("select name, class_id from characters order by class_id ASC ;",null,(err,result,next) => {
console.log("result",result);
next();
});
yield db.query("select name from characters ;");
if (db.error()) {
console.log("error:",db.error);
db.end();
return;
}
var rows = db.rows; //array
console.log("rows",rows);
var i = 0;
for (var value of db.rows) {
console.log(i,value);
i++;
}
console.log("");
console.log("Start of asyncForEach:");
yield db.asyncForEach((index,item,next) => {
console.log(item);
next();
});
console.log("End of asyncForEach");
console.log("");
yield db.end();
console.log("end of db test");
})();