forked from sql-js/sql.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.html
34 lines (30 loc) · 962 Bytes
/
repl.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
<!doctype html>
<html>
<!--Simple Read eval print loop for SQL-->
<head>
<meta charset="utf8">
<title>SQL REPL</title>
<script src="../dist/sql-wasm.js"></script>
</head>
<body>
<input type='text' id='input' placeholder="ENTER SOME SQL" size='50'
value="CREATE TABLE test(val);INSERT INTO test VALUES (666); SELECT * FROM test">
<button id='submit'>Execute</button>
<pre id='result'></pre>
<pre id='error'></pre>
<script>
//Open a blank database
var db;
initSqlJs({ locateFile: filename => `../dist/${filename}` }).then(function (SQL) {
db = new SQL.Database();
});
document.getElementById('submit').onclick = function () {
var sql = document.getElementById('input').value;
var result = '', error = '';
try { result = db.exec(sql); }
catch (e) { error = e; }
document.getElementById('result').innerHTML = JSON.stringify(result, null, ' ');
document.getElementById('error').innerHTML = error;
};
</script>
</body>