forked from sql-js/sql.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.html
38 lines (34 loc) · 1.2 KB
/
simple.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
<meta charset="utf8" />
<html>
<script src='../dist/sql-wasm-debug.js'></script>
<script>
config = {
locateFile: (filename, prefix) => {
console.log(`prefix is : ${prefix}`);
return `../dist/${filename}`;
}
}
// The `initSqlJs` function is globally provided by all of the main dist files if loaded in the browser.
// We must specify this locateFile function if we are loading a wasm file from anywhere other than the current html page's folder.
initSqlJs(config).then(function (SQL) {
//Create the database
var db = new SQL.Database();
// Run a query without reading the results
db.run("CREATE TABLE test (col1, col2);");
// Insert two rows: (1,111) and (2,222)
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1, 111, 2, 222]);
// Prepare a statement
var stmt = db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");
stmt.getAsObject({ $start: 1, $end: 1 }); // {col1:1, col2:111}
// Bind new values
stmt.bind({ $start: 1, $end: 2 });
while (stmt.step()) { //
var row = stmt.getAsObject();
console.log('Here is a row: ' + JSON.stringify(row));
}
});
</script>
<body>
Output is in Javscript console
</body>
</html>