forked from macc704/isfw2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osql.js
51 lines (46 loc) · 1.34 KB
/
osql.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
/**
* osql.js oursqlにアクセスするためのライブラリ
* setting.jsにサーバ情報を書き込んで利用する
*
* version 1.0.0 2021.04.27
*/
var osql = {};
osql.connect = function (sql) {
console.log(sql);
var query = {};
query.userid = settings.userid;
query.password = settings.password;
query.db = settings.db;
query.sql = sql;
return new Promise(function (resolve) {
$.post(settings.apiurl, query, function (data, textStatus) {
try {
if (data && data.startsWith('Error:')) {
console.error(sql);
console.error(data);
window.alert(data + '\n' + sql);
return;
}
var objects = JSON.parse(data);
resolve(objects);
} catch (ex) {
console.error(ex);
console.error(sql);
}
});
});
}
osql.getParams = function () {
var paramstr = document.location.search.substring(1);
paramstr = decodeURI(paramstr);
var paramstrs = paramstr.split('&');
params = {};
paramstrs.forEach(function (each) {
var tokens = each.split('=');
params[tokens[0]] = tokens[1];
});
return params;
};
osql.getParam = function (key) {
return osql.getParams()[key];
};