myadapter.js
1.9 KB
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
function apiadapter(payload) {
var moduleName = payload.moduleName;
var method = payload.method;
var isSync = payload.isSync;
var params = payload.params;
var cbId = payload.cbId;
var callback = payload.callback;
var frameDom = payload.frameDom;
var winDom = payload.winDom;
var apiDom = payload.apiDom;
if (moduleName === 'db') {
if (method === 'openDatabase') {
callback(cbId, { status: true }, null, true);
return;
}
if (method === 'executeSql') {
var _ret = (function () {
var name = params.name;
var sql = params.sql;
var db = openDatabase(name, '1.0', 'APICloud App Database', 2 * 1024 * 1024);
db.transaction(function (ctx) {
ctx.executeSql(sql, [], function (ctx, result) {
callback(cbId, { status: true }, null, true);
}, function (ctx, error) {
callback(cbId, { status: false }, { msg: error && error.message }, true);
});
});
return {
v: undefined
};
})();
if (typeof _ret === 'object') return _ret.v;
}
if (method === 'selectSql') {
var _ret2 = (function () {
var name = params.name;
var sql = params.sql;
var db = openDatabase(name, '1.0', 'APICloud App Database', 2 * 1024 * 1024);
db.transaction(function (ctx) {
ctx.executeSql(sql, [], function (ctx, result) {
var len = result.rows.length;
var data = [];
for (var i = 0; i < len; i++) {
data.push(result.rows.item(i));
}
callback(cbId, { status: true, data: data }, null, true);
}, function (ctx, error) {
callback(cbId, { status: false }, { msg: error && error.message });
});
});
return {
v: undefined
};
})();
if (typeof _ret2 === 'object') return _ret2.v;
}
}
return 'TO_NEXT_API_ADAPTER';
}