From b047e1e4c68dba8daec34ac4a64c2a64139a7f94 Mon Sep 17 00:00:00 2001 From: DhivinX Date: Tue, 6 Aug 2024 17:18:53 +0200 Subject: [PATCH 1/3] chore: add build with sql.js script --- README.md | 2 +- package.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a9ea46b..670b966 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ The full code of this example is in [example/](./example/). ## Compiling -To compile this project (only needed if you want to modify the library itself), make sure you have emscripten, then first compile sql.js, then sql.js-httpvfs: +To compile this project (only needed if you want to modify the library itself), make sure you have emscripten (min. 3.1.0), then first compile sql.js, then sql.js-httpvfs: ``` cd sql.js diff --git a/package.json b/package.json index 3a14073..bd4c3dc 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "license": "Apache-2.0", "scripts": { "dev": "webpack serve --mode=development", - "build": "webpack build --mode=production" + "build": "webpack build --mode=production", + "build-sql": "cd sql.js && yarn build && cd .. && webpack build --mode=production" }, "dependencies": { "comlink": "^4.3.0" @@ -30,4 +31,4 @@ "files": [ "dist/*" ] -} +} \ No newline at end of file From 8958a4d8bfd0c58142d19c0bd9ded283f7187741 Mon Sep 17 00:00:00 2001 From: DhivinX Date: Tue, 6 Aug 2024 17:19:36 +0200 Subject: [PATCH 2/3] feat: add headUrl as optional parameter --- src/lazyFile.ts | 4 ++-- src/sqlite.worker.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lazyFile.ts b/src/lazyFile.ts index 1d27511..b82b781 100644 --- a/src/lazyFile.ts +++ b/src/lazyFile.ts @@ -6,7 +6,7 @@ export type RangeMapper = ( fromByte: number, toByte: number -) => { url: string; fromByte: number; toByte: number }; +) => { url: string; headUrl: string; fromByte: number; toByte: number }; export type RequestLimiter = (bytes: number) => void; @@ -169,7 +169,7 @@ export class LazyUint8Array { /** verify the server supports range requests and find out file length */ private checkServer() { var xhr = new XMLHttpRequest(); - const url = this.rangeMapper(0, 0).url; + const url = this.rangeMapper(0, 0).headUrl; // can't set Accept-Encoding header :( https://stackoverflow.com/questions/41701849/cannot-modify-accept-encoding-with-fetch xhr.open("HEAD", url, false); // // maybe this will help it not use compression? diff --git a/src/sqlite.worker.ts b/src/sqlite.worker.ts index fef355a..ecb7419 100644 --- a/src/sqlite.worker.ts +++ b/src/sqlite.worker.ts @@ -1,10 +1,10 @@ /// import * as Comlink from "comlink"; +import { Database, QueryExecResult } from "sql.js"; import initSqlJs from "../sql.js/dist/sql-wasm.js"; import wasmUrl from "../sql.js/dist/sql-wasm.wasm"; import { createLazyFile, LazyUint8Array, PageReadLog, RangeMapper } from "./lazyFile"; -import { Database, QueryExecResult } from "sql.js"; import { SeriesVtab, sqlite3_module, SqljsEmscriptenModuleType } from "./vtab"; wasmUrl; @@ -71,6 +71,7 @@ export type SplitFileConfigInner = { | { serverMode: "full"; url: string; + headUrl?: string; } ); export interface LazyHttpDatabase extends Database { @@ -115,6 +116,7 @@ async function fetchConfigs( : { ...configOut, url: new URL(configOut.url, configUrl).toString(), + headUrl: configOut.headUrl ? new URL(configOut.headUrl, configUrl).toString() : new URL(configOut.url, configUrl).toString(), }, virtualFilename: config.virtualFilename, } as SplitFileConfigPure; @@ -171,6 +173,7 @@ const mod = { const serverTo = serverFrom + (to - from); return { url: config.urlPrefix + String(serverChunkId).padStart(config.suffixLength, "0") + suffix, + headUrl: config.headUrl ?? config.urlPrefix + String(serverChunkId).padStart(config.suffixLength, "0") + suffix, fromByte: serverFrom, toByte: serverTo, }; @@ -178,6 +181,7 @@ const mod = { } else { rangeMapper = (fromByte, toByte) => ({ url: config.url + suffix, + headUrl: config.headUrl ? config.headUrl + suffix : config.url + suffix, fromByte, toByte, }); @@ -189,7 +193,7 @@ const mod = { mainVirtualFilename = filename; mainFileConfig = config } - console.log("filename", filename); + console.log("constructing url database", id, "filename", filename); const lazyFile = createLazyFile(sql.FS, "/", filename, true, true, { rangeMapper, From c109432f6c8d94eb92f90683951ace566c5c8e18 Mon Sep 17 00:00:00 2001 From: DhivinX Date: Tue, 6 Aug 2024 17:20:02 +0200 Subject: [PATCH 3/3] chore: remove LEGACY_RUNTIME --- sql.js/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql.js/Makefile b/sql.js/Makefile index aa27063..d650207 100644 --- a/sql.js/Makefile +++ b/sql.js/Makefile @@ -39,8 +39,7 @@ EMFLAGS = \ -s EXTRA_EXPORTED_RUNTIME_METHODS=@src/exported_runtime_methods.json \ -s SINGLE_FILE=0 \ -s NODEJS_CATCH_EXIT=0 \ - -s NODEJS_CATCH_REJECTION=0 \ - -s LEGACY_RUNTIME=1 + -s NODEJS_CATCH_REJECTION=0 # -s ASYNCIFY=1 \ # -s ASYNCIFY_IMPORTS='["sqlite3VdbeExec"]'