Skip to content

Commit 2e4361c

Browse files
committed
first working SQL statement
0 parents  commit 2e4361c

12 files changed

+4246
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/deps

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# sqlite-wasm-http
2+
3+
An experimental HTTP VFS driver for SQLite WASM

build_sqlite.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source ../emsdk/emsdk_env.sh
2+
cd deps/sqlite
3+
./configure --enable-all
4+
cd ext/wasm
5+
make -j4

examples/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en-us">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7+
<title>Hello, sqlite3</title>
8+
</head>
9+
10+
<body>
11+
</body>
12+
13+
</html>

examples/index.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sqlite3 from '../deps/sqlite/ext/wasm/jswasm/sqlite3-bundler-friendly.mjs';
2+
3+
import '../deps/sqlite/ext/wasm/jswasm/sqlite3-worker1-promiser-bundler-friendly.js';
4+
5+
const promiser = sqlite3Worker1Promiser({
6+
onready: () => {
7+
promiser('config-get', {})
8+
.then((r) => console.log(r));
9+
promiser('open', {
10+
filename: 'file:' +
11+
encodeURI('http://sokol.garga/maptiler-osm-2017-07-03-v3.6.1-europe.mbtiles') +
12+
'?vfs=http&mode=ro'
13+
})
14+
.then((msg) => {
15+
console.log(msg);
16+
return promiser('exec', {
17+
sql: 'select * from tiles where zoom_level = 1',
18+
callback: function(row) {
19+
console.log('got row', row);
20+
}
21+
})
22+
})
23+
.then((msg) => {
24+
console.log(msg);
25+
});
26+
},
27+
worker: () => {
28+
const w = new Worker(new URL('./worker.js', import.meta.url));
29+
w.onerror = (event) => console.error("worker.onerror", event);
30+
return w;
31+
}
32+
});

examples/worker.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sqlite3 from '../deps/sqlite/ext/wasm/jswasm/sqlite3-bundler-friendly.mjs';
2+
import { installhttpVfs } from '../src/sqlite3-vfs-http.js';
3+
import { createHttpBackend } from '../src/sqlite3-vfs-http-muxer';
4+
5+
const backend = createHttpBackend();
6+
Promise.all([sqlite3(), backend.createNewChannel()])
7+
.then(([sqlite3, channel]) => {
8+
console.log('sqlite loaded', sqlite3);
9+
console.log('got new channel', channel);
10+
sqlite3.initWorker1API();
11+
console.log('sqlite initialized', sqlite3);
12+
installhttpVfs(sqlite3, { backend: channel });
13+
});

0 commit comments

Comments
 (0)