spl.js 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +1 -1
- package/dist/index.wasm +0 -0
- package/dist/spl-node.mjs +1 -1
- package/dist/spl-web.js +1 -1
- package/examples/transform.html +45 -0
- package/package.json +1 -1
- package/src/spl.js +7 -4
- package/test/browser.js +50 -0
- package/test/files/json/precision.json +6970 -0
- package/test/node.js +29 -3
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Transform</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<pre id="time"></pre>
|
|
9
|
+
<script type="module">
|
|
10
|
+
|
|
11
|
+
import SPL from '../dist/index.js';
|
|
12
|
+
|
|
13
|
+
const extension = {
|
|
14
|
+
extends: 'db',
|
|
15
|
+
fns: {
|
|
16
|
+
'transform': db => {
|
|
17
|
+
const time = []
|
|
18
|
+
for (let i = 0; i < 50; i++) {
|
|
19
|
+
const t = Date.now();
|
|
20
|
+
db.exec("select st_transform(st_transform(MakePoint (-22562.401432422717, 6730934.887787993, 3857), 27700), 3857)");
|
|
21
|
+
time.push(Date.now() - t);
|
|
22
|
+
}
|
|
23
|
+
return time;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const proj = await fetch('../dist/proj/proj.db').then(data => data.arrayBuffer())
|
|
29
|
+
const spl = await SPL({}, [extension]);
|
|
30
|
+
const db = await spl
|
|
31
|
+
.mount('proj', [
|
|
32
|
+
{ name: 'proj.db', data: proj }
|
|
33
|
+
])
|
|
34
|
+
.db()
|
|
35
|
+
.read(`
|
|
36
|
+
select PROJ_SetDatabasePath('/proj/proj.db');
|
|
37
|
+
select initspatialmetadata(1);
|
|
38
|
+
`);
|
|
39
|
+
|
|
40
|
+
const el = document.getElementById("time")
|
|
41
|
+
el.innerHTML = await db.transform();
|
|
42
|
+
|
|
43
|
+
</script>
|
|
44
|
+
</body>
|
|
45
|
+
</html>
|
package/package.json
CHANGED
package/src/spl.js
CHANGED
|
@@ -43,7 +43,6 @@ const spl = function (wasmBinary=null, options = {}) {
|
|
|
43
43
|
getValue,
|
|
44
44
|
setValue,
|
|
45
45
|
stackAlloc,
|
|
46
|
-
HEAP8,
|
|
47
46
|
stringToUTF8,
|
|
48
47
|
UTF8ToString,
|
|
49
48
|
lengthBytesUTF8,
|
|
@@ -66,7 +65,7 @@ const spl = function (wasmBinary=null, options = {}) {
|
|
|
66
65
|
|
|
67
66
|
const sqlite3_open = _emspl.cwrap('sqlite3_open', 'number', ['string', 'number']),
|
|
68
67
|
sqlite3_close_v2 = _emspl.cwrap('sqlite3_close_v2', 'number', ['number']),
|
|
69
|
-
sqlite3_prepare_v2 = _emspl.cwrap('sqlite3_prepare_v2', 'number', ['number', '
|
|
68
|
+
sqlite3_prepare_v2 = _emspl.cwrap('sqlite3_prepare_v2', 'number', ['number', 'number', 'number', 'number', 'number']),
|
|
70
69
|
sqlite3_bind_text = _emspl.cwrap('sqlite3_bind_text', 'number', ['number', 'number', 'number', 'number', 'number']),
|
|
71
70
|
sqlite3_bind_blob = _emspl.cwrap('sqlite3_bind_blob', 'number', ['number', 'number', 'number', 'number', 'number']),
|
|
72
71
|
sqlite3_bind_double = _emspl.cwrap('sqlite3_bind_double', 'number', ['number', 'number', 'number']),
|
|
@@ -272,8 +271,11 @@ const spl = function (wasmBinary=null, options = {}) {
|
|
|
272
271
|
let ret, ptrs = [];
|
|
273
272
|
const rows = [];
|
|
274
273
|
setValue(tmpPtr, 0, 'i32');
|
|
274
|
+
const sqlSize = lengthBytesUTF8(sql) + 1
|
|
275
|
+
const sqlPtr = _malloc(sqlSize);
|
|
276
|
+
stringToUTF8(sql, sqlPtr, sqlSize);
|
|
275
277
|
|
|
276
|
-
ret = sqlite3_prepare_v2(dbHandle,
|
|
278
|
+
ret = sqlite3_prepare_v2(dbHandle, sqlPtr, -1, tmpPtr, 0);
|
|
277
279
|
if (ret !== SQLITE.OK) {
|
|
278
280
|
throw new Error(sqlite3_errmsg(dbHandle));
|
|
279
281
|
}
|
|
@@ -424,7 +426,7 @@ const spl = function (wasmBinary=null, options = {}) {
|
|
|
424
426
|
if (splOptions.autoGeoJSON && isGaia(ptr, size)) {
|
|
425
427
|
val = toGeoJSON(ptr, size, splOptions.autoGeoJSON.precision, splOptions.autoGeoJSON.options);
|
|
426
428
|
} else {
|
|
427
|
-
val = HEAP8.buffer.slice(ptr, ptr + size);
|
|
429
|
+
val = _emspl.HEAP8.buffer.slice(ptr, ptr + size);
|
|
428
430
|
}
|
|
429
431
|
break;
|
|
430
432
|
default:
|
|
@@ -449,6 +451,7 @@ const spl = function (wasmBinary=null, options = {}) {
|
|
|
449
451
|
|
|
450
452
|
// const readonly = sqlite3_stmt_readonly(stmt);
|
|
451
453
|
sqlite3_finalize(stmt);
|
|
454
|
+
_free(sqlPtr);
|
|
452
455
|
|
|
453
456
|
_result = result(columns, rows);
|
|
454
457
|
|
package/test/browser.js
CHANGED
|
@@ -213,3 +213,53 @@ tape('extensions', async t => {
|
|
|
213
213
|
);
|
|
214
214
|
|
|
215
215
|
});
|
|
216
|
+
|
|
217
|
+
tape('json', async t => {
|
|
218
|
+
|
|
219
|
+
t.plan(4);
|
|
220
|
+
|
|
221
|
+
let db = (await SPL({
|
|
222
|
+
autoGeoJSON: {
|
|
223
|
+
precision: 0,
|
|
224
|
+
options: 0
|
|
225
|
+
}
|
|
226
|
+
})).db();
|
|
227
|
+
|
|
228
|
+
t.deepEqual(
|
|
229
|
+
await db.exec('select json(@js)', { '@js': { hello: 'json' }}).get.first,
|
|
230
|
+
{ hello: 'json' }
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
t.deepEqual(
|
|
234
|
+
await db.exec('select geomfromtext(?)', [ 'POINT(11.1 11.1)' ]).get.first,
|
|
235
|
+
{ type: 'Point', 'coordinates': [11, 11] }
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
db.close();
|
|
239
|
+
|
|
240
|
+
// https://github.com/jvail/spl.js/issues/33
|
|
241
|
+
db = (await SPL({
|
|
242
|
+
autoGeoJSON: {
|
|
243
|
+
precision: 8,
|
|
244
|
+
options: 0
|
|
245
|
+
}
|
|
246
|
+
})).db();
|
|
247
|
+
|
|
248
|
+
const [a, b] = await fetch('files/json/precision.json').then(res => res.json());
|
|
249
|
+
|
|
250
|
+
t.doesNotThrow(
|
|
251
|
+
async () => await db.exec(
|
|
252
|
+
'SELECT CastToMulti(ST_Union(GeomFromGeoJSON(@a), GeomFromGeoJSON(@b)))',
|
|
253
|
+
{ '@a': a, '@b': b }
|
|
254
|
+
).get.first
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
t.doesNotThrow(
|
|
258
|
+
async () => await db.exec(
|
|
259
|
+
`SELECT CastToMulti(ST_Union(GeomFromGeoJSON('${JSON.stringify(a)}'), GeomFromGeoJSON('${JSON.stringify(b)}'))) as a`
|
|
260
|
+
).get.first
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
db.close();
|
|
264
|
+
|
|
265
|
+
});
|