-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
114 lines (105 loc) · 4.88 KB
/
index.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<html>
<head>
<meta charset="UTF-8">
<title>SamehadaDB Simple Client Demo</title>
<style>
input.queryform {
width: 50%;
}
input.serveraddress {
width: 25%;
}
</style>
<script type="text/javascript" src="./jquery-3.7.1.min.js"></script>
<script src="./jquery.binarytransport.js"></script>
<script src="./msgpack.min.js"></script>
<script type="text/javascript">
var executedLog = "";
function handleDecoded(queryStr, data) {
$("#result-error").html(String(data.Error));
var resultStr = "";
if (data.Result != null && data.Result != undefined && data.length != 0) {
for (var ii = 0; ii < data.Result.length; ii++) {
var rowStr = "";
for (var jj = 0; jj < data.Result[ii].C.length; jj++) {
if (typeof data.Result[ii].C[jj] == "string") {
rowStr += '"' + data.Result[ii].C[jj] + '" ,';
} else {
rowStr += data.Result[ii].C[jj] + " ,";
}
}
resultStr += rowStr + "<br />"
}
resultStr = queryStr + "<br />" + resultStr + "<br />"
executedLog += resultStr;
$("#result-main").html(executedLog);
}
}
function getRandomInt(min, max) {
var min = Math.ceil(min);
var max = Math.floor(max);
//The maximum is exclusive and the minimum is inclusive
return Math.floor(Math.random() * (max - min) + min);
}
$(document).ready(function () {
var queryStrTmp = $('#queryform [name=queryform]');
queryStrTmp.val("{\"Query\":\"CREATE TABLE name_age_list_" + String(getRandomInt(100, 10000)) + "(name VARCHAR(256), age INT);\"}");
$("#issue1").click(function () {
var queryStr = $('#queryform [name=queryform]').val();
var serverAddress = $('#serveraddress [name=serveraddress]').val();
$.ajax({
type: "POST",
url: "http://" + serverAddress + "/Query",
contentType: "application/json;charset=utf-8",
data: queryStr,
}).done(function (data) {
console.log(data);
handleDecoded(queryStr, data);
}).fail(function (jqXHR, textStatus, errorThrown) {
$("#result-error").html("Error: " + textStatus + " " + errorThrown);
});
});
});
$(document).ready(function () {
$("#issue2").click(function () {
var queryStr = $('#queryform [name=queryform]').val();
var serverAddress = $('#serveraddress [name=serveraddress]').val();
$.ajax({
type: "POST",
url: "http://" + serverAddress + "/QueryMsgPack",
contentType: "application/json;charset=utf-8",
responseType: "arraybuffer",
dataType: "binary",
data: queryStr,
}).done(function (data) {
data = msgpack.deserialize(data);
handleDecoded(queryStr, data);
}).fail(function (jqXHR, textStatus, errorThrown) {
$("#result-error").html("Error: " + textStatus + " " + errorThrown);
});
});
});
</script>
</head>
<body>
<h1><a href="https://github.com/ryogrid/SamehadaDB">SamehadaDB</a> Simple Client Demo<br />
(SPA which accesses RESTxJSON and RESTxJSONxMessagePack I/F)</h1>
<p>server address</p>
<form id="serveraddress">
<input type="text" class="serveraddress" name="serveraddress" value="ryogrid.net:19999" />
</form>
<p>query</p>
<form id="queryform">
<input type="text" class="queryform" name="queryform"
value="{"Query":"CREATE TABLE name_age_list(name VARCHAR(256), age INT);"}" />
</form>
<br />
<button id="issue1">send (JSON respons I/F)</button><br/>
<button id="issue2">send (MessagePack respons I/F)</button><br/>
<br />
<br />
<div id="result-error"></div>
<br />
<div id="result-main"></div>
</body>
</html>