forked from sql-js/sql.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
60 lines (53 loc) · 2.03 KB
/
demo.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
<html>
<head>
<title>
sql.js
</title>
<script src="sql.js"></script>
<script>
// Connect to the HTML element we 'print' to
function print(text) {
var element = document.getElementById('output');
element.innerHTML = text.replace(/\n/g, '<br>');
}
// Open a database
var db = SQL.open();
// Run a command in the database
function execute(commands) {
try {
var data = db.exec(commands.replace(/\n/g, '; '));
print(JSON.stringify(data, null, ' '));
} catch(e) {
print(e);
}
}
</script>
</head>
<body>
<p>
This is <a href="https://github.com/kripken/sql.js">sql.js</a>: <a href="http://www.sqlite.org/">SQLite</a> compiled from C to JavaScript using <a href="http://emscripten.org">Emscripten</a>. View this page's source to see how easy it is to use it!
</p>
<p>
<ul>
<li>This is <b>not</b> a fully optimized build (optimized builds break both <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=733208">Firefox</a> and <a href="http://code.google.com/p/v8/issues/detail?id=1986">Chrome</a>).</li>
</ul>
</p>
<hr>
<form onsubmit="execute(commands.value); return false">
<b>Enter some SQL</b>:
<br>
<textarea rows="10" cols="80" id="commands">CREATE TABLE my_table(key INTEGER, value INTEGER, text VARCHAR(100));
INSERT INTO my_table VALUES(1, 25, 'the first item');
INSERT INTO my_table VALUES(2, 987, 'the second item');
SELECT key, text FROM my_table WHERE value == 987;
</textarea>
<br>
<input type="submit" value="execute">
</form>
<hr>
<pre>
<div id="output" style="font-family: Courier New,Courier,monospace;"></div>
</pre>
<a href="https://github.com/kripken/sql.js"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/abad93f42020b733148435e2cd92ce15c542d320/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub"></a>
</body>
</html>