From 88c0b1dd587364ee5fceae4ddff36872af4e6a53 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 4 Mar 2026 02:05:13 +0100 Subject: [PATCH 1/6] fix https://github.com/sql-js/sql.js/issues/624 --- package-lock.json | 221 +++++++++++++++++++------------------------ package.json | 4 +- src/api.js | 42 ++++---- test/load_sql_lib.js | 12 ++- test/test_worker.js | 5 + 5 files changed, 137 insertions(+), 147 deletions(-) diff --git a/package-lock.json b/package-lock.json index e0110965..905116c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -85,6 +85,19 @@ "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, + "node_modules/@eslint-community/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, "node_modules/@eslint-community/regexpp": { "version": "4.12.2", "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.2.tgz", @@ -96,36 +109,20 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.1.tgz", - "integrity": "sha512-uVSdg/V4dfQmTjJzR0szNczjOH/J+FyUMMjYtr07xFRXR7EDf9i1qdxrD0VusZH9knj1/ecxzCQQxyic5NzAiA==", + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.2.tgz", + "integrity": "sha512-YF+fE6LV4v5MGWRGj7G404/OZzGNepVF8fxk7jqmqo3lrza7a0uUcDnROGRBG1WFC1omYUS/Wp1f42i0M+3Q3A==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@eslint/object-schema": "^3.0.1", + "@eslint/object-schema": "^3.0.2", "debug": "^4.3.1", - "minimatch": "^10.1.1" + "minimatch": "^10.2.1" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" } }, - "node_modules/@eslint/config-array/node_modules/minimatch": { - "version": "10.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.2.tgz", - "integrity": "sha512-fu656aJ0n2kcXwsnwnv9g24tkU5uSmOlTjd6WyyaKm2Z+h1qmY6bAjrcaIxF/BslFqbZ8UBtbJi7KgQOZD2PTw==", - "dev": true, - "license": "BlueOak-1.0.0", - "dependencies": { - "@isaacs/brace-expansion": "^5.0.1" - }, - "engines": { - "node": "20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/@eslint/config-helpers": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.5.2.tgz", @@ -174,9 +171,9 @@ } }, "node_modules/@eslint/object-schema": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-3.0.1.tgz", - "integrity": "sha512-P9cq2dpr+LU8j3qbLygLcSZrl2/ds/pUpfnHNNuk5HW7mnngHs+6WSq5C9mO3rqRX8A1poxqLTC9cu0KOyJlBg==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-3.0.2.tgz", + "integrity": "sha512-HOy56KJt48Bx8KmJ+XGQNSUMT/6dZee/M54XyUyuvTvPXJmsERRvBchsUVx1UMe1WwIH49XLAczNC7V2INsuUw==", "dev": true, "license": "Apache-2.0", "engines": { @@ -249,29 +246,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@isaacs/balanced-match": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz", - "integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": "20 || >=22" - } - }, - "node_modules/@isaacs/brace-expansion": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.1.tgz", - "integrity": "sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@isaacs/balanced-match": "^4.0.1" - }, - "engines": { - "node": "20 || >=22" - } - }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", @@ -323,13 +297,13 @@ } }, "node_modules/@jsdoc/salty": { - "version": "0.2.9", - "resolved": "https://registry.npmjs.org/@jsdoc/salty/-/salty-0.2.9.tgz", - "integrity": "sha512-yYxMVH7Dqw6nO0d5NIV8OQWnitU8k6vXH8NtgqAfIa/IUqRMxRv/NUJJ08VEKbAakwxlgBl5PJdrU0dMPStsnw==", + "version": "0.2.10", + "resolved": "https://registry.npmjs.org/@jsdoc/salty/-/salty-0.2.10.tgz", + "integrity": "sha512-VFHSsQAQp8y1NJvAJBpLs9I2shHE6hz9TwukocDObuUgGVAq62yZGbTgJg04Z3Fj0XSMWe0sJqGg5dhKGTV92A==", "dev": true, "license": "Apache-2.0", "dependencies": { - "lodash": "^4.17.21" + "lodash": "^4.17.23" }, "engines": { "node": ">=v12.0.0" @@ -382,9 +356,9 @@ "license": "MIT" }, "node_modules/acorn": { - "version": "8.15.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", - "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", + "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, "license": "MIT", "bin": { @@ -405,9 +379,9 @@ } }, "node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz", + "integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==", "dev": true, "license": "MIT", "dependencies": { @@ -428,6 +402,16 @@ "dev": true, "license": "Python-2.0" }, + "node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -435,6 +419,19 @@ "dev": true, "license": "MIT" }, + "node_modules/brace-expansion": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz", + "integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -585,15 +582,15 @@ } }, "node_modules/eslint": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.0.0.tgz", - "integrity": "sha512-O0piBKY36YSJhlFSG8p9VUdPV/SxxS4FYDWVpr/9GJuMaepzwlf4J8I4ov1b+ySQfDTPhc3DtLaxcT1fN0yqCg==", + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.0.2.tgz", + "integrity": "sha512-uYixubwmqJZH+KLVYIVKY1JQt7tysXhtj21WSvjcSmU5SVNzMus1bgLe+pAt816yQ8opKfheVVoPLqvVMGejYw==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.2", - "@eslint/config-array": "^0.23.0", + "@eslint/config-array": "^0.23.2", "@eslint/config-helpers": "^0.5.2", "@eslint/core": "^1.1.0", "@eslint/plugin-kit": "^0.6.0", @@ -601,13 +598,13 @@ "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", - "ajv": "^6.12.4", + "ajv": "^6.14.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^9.1.0", - "eslint-visitor-keys": "^5.0.0", - "espree": "^11.1.0", + "eslint-scope": "^9.1.1", + "eslint-visitor-keys": "^5.0.1", + "espree": "^11.1.1", "esquery": "^1.7.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -618,7 +615,7 @@ "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", - "minimatch": "^10.1.1", + "minimatch": "^10.2.1", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, @@ -641,9 +638,9 @@ } }, "node_modules/eslint-scope": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-9.1.0.tgz", - "integrity": "sha512-CkWE42hOJsNj9FJRaoMX9waUFYhqY4jmyLFdAdzZr6VaCg3ynLYx4WnOdkaIifGfH4gsUcBTn4OZbHXkpLD0FQ==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-9.1.1.tgz", + "integrity": "sha512-GaUN0sWim5qc8KVErfPBWmc31LEsOkrUJbvJZV+xuL3u2phMUK4HIvXlWAakfC8W4nzlK+chPEAkYOYb5ZScIw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -660,22 +657,9 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", - "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", - "dev": true, - "license": "Apache-2.0", - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.0.tgz", - "integrity": "sha512-A0XeIi7CXU7nPlfHS9loMYEKxUaONu/hTEzHTGba9Huu94Cq1hPivf+DE5erJozZOky0LfvXAyrV/tcswpLI0Q==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", + "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", "dev": true, "license": "Apache-2.0", "engines": { @@ -685,32 +669,16 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint/node_modules/minimatch": { - "version": "10.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.2.tgz", - "integrity": "sha512-fu656aJ0n2kcXwsnwnv9g24tkU5uSmOlTjd6WyyaKm2Z+h1qmY6bAjrcaIxF/BslFqbZ8UBtbJi7KgQOZD2PTw==", - "dev": true, - "license": "BlueOak-1.0.0", - "dependencies": { - "@isaacs/brace-expansion": "^5.0.1" - }, - "engines": { - "node": "20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/espree": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-11.1.0.tgz", - "integrity": "sha512-WFWYhO1fV4iYkqOOvq8FbqIhr2pYfoDY0kCotMkDeNtGpiGGkZ1iov2u8ydjtgM8yF8rzK7oaTbw2NAzbAbehw==", + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-11.1.1.tgz", + "integrity": "sha512-AVHPqQoZYc+RUM4/3Ly5udlZY/U4LS8pIG05jEjWM2lQMU/oaZ7qshzAl2YP1tfNmXfftH3ohurfwNAug+MnsQ==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.15.0", + "acorn": "^8.16.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^5.0.0" + "eslint-visitor-keys": "^5.0.1" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" @@ -719,19 +687,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.0.tgz", - "integrity": "sha512-A0XeIi7CXU7nPlfHS9loMYEKxUaONu/hTEzHTGba9Huu94Cq1hPivf+DE5erJozZOky0LfvXAyrV/tcswpLI0Q==", - "dev": true, - "license": "Apache-2.0", - "engines": { - "node": "^20.19.0 || ^22.13.0 || >=24" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, "node_modules/esquery": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.7.0.tgz", @@ -844,9 +799,9 @@ } }, "node_modules/flatted": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.3.tgz", - "integrity": "sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==", + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.4.tgz", + "integrity": "sha512-3+mMldrTAPdta5kjX2G2J7iX4zxtnwpdA8Tr2ZSjkyPSanvbZAcy6flmtnXbEybHrDcU9641lxrMfFuUxVz9vA==", "dev": true, "license": "ISC" }, @@ -1190,6 +1145,22 @@ "dev": true, "license": "MIT" }, + "node_modules/minimatch": { + "version": "10.2.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.4.tgz", + "integrity": "sha512-oRjTw/97aTBN0RHbYCdtF1MQfvusSIBQM0IZEgzl6426+8jSC0nF1a/GmnVLpfB9yyr6g6FTqWqiZVbxrtaCIg==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/mkdirp": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", @@ -1508,9 +1479,9 @@ "license": "MIT" }, "node_modules/underscore": { - "version": "1.13.7", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.7.tgz", - "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==", + "version": "1.13.8", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.8.tgz", + "integrity": "sha512-DXtD3ZtEQzc7M8m4cXotyHR+FAS18C64asBYY5vqZexfYryNNnDc02W4hKg3rdQuqOYas1jkseX0+nZXjTXnvQ==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index ef838bcc..2da19a50 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "build": "make", "rebuild": "npm run clean && npm run build", "clean": "make clean", - "test": "npm run lint && npm run test-asm && npm run test-asm-debug && npm run test-wasm && npm run test-wasm-debug && npm run test-asm-memory-growth", + "test": "npm run lint && npm run test-asm && npm run test-asm-debug && npm run test-wasm && npm run test-wasm-debug && npm run test-wasm-browser && npm run test-wasm-browser-debug && npm run test-asm-memory-growth", "lint": "eslint .", "prettify": "eslint . --fix", "test-asm": "node --unhandled-rejections=strict test/all.js asm", @@ -37,6 +37,8 @@ "test-asm-memory-growth": "node --unhandled-rejections=strict test/all.js asm-memory-growth", "test-wasm": "node --unhandled-rejections=strict test/all.js wasm", "test-wasm-debug": "node --unhandled-rejections=strict test/all.js wasm-debug", + "test-wasm-browser": "node --unhandled-rejections=strict test/all.js wasm-browser", + "test-wasm-browser-debug": "node --unhandled-rejections=strict test/all.js wasm-browser-debug", "doc": "jsdoc -c .jsdoc.config.json" }, "homepage": "http://github.com/sql-js/sql.js", diff --git a/src/api.js b/src/api.js index c7f102b7..2e05a481 100644 --- a/src/api.js +++ b/src/api.js @@ -357,7 +357,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { case SQLITE_DONE: return false; default: - throw this.db.handleError(ret); + throw this.db["handleError"](ret); } }; @@ -417,11 +417,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @example Print all the rows of the table test to the console var stmt = db.prepare("SELECT * FROM test"); - while (stmt.step()) console.log(stmt.get()); + while (stmt["step"]()) console.log(stmt.get()); Enable BigInt support var stmt = db.prepare("SELECT * FROM test"); - while (stmt.step()) console.log(stmt.get(null, {useBigInt: true})); + while (stmt["step"]()) console.log(stmt.get(null, {useBigInt: true})); */ Statement.prototype["get"] = function get(params, config) { config = config || {}; @@ -460,7 +460,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var stmt = db.prepare( "SELECT 5 AS nbr, x'616200' AS data, NULL AS null_value;" ); - stmt.step(); // Execute the statement + stmt["step"](); // Execute the statement console.log(stmt.getColumnNames()); // Will print ['nbr','data','null_value'] */ @@ -485,7 +485,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var stmt = db.prepare( "SELECT 5 AS nbr, x'010203' AS data, NULL AS null_value;" ); - stmt.step(); // Execute the statement + stmt["step"](); // Execute the statement console.log(stmt.getAsObject()); // Will print {nbr:5, data: Uint8Array([1,2,3]), null_value:null} */ @@ -543,7 +543,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { } var strptr = stringToNewUTF8(string); this.allocatedmem.push(strptr); - this.db.handleError(sqlite3_bind_text( + this.db["handleError"](sqlite3_bind_text( this.stmt, pos, strptr, @@ -561,7 +561,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var blobptr = _malloc(array.length); writeArrayToMemory(array, blobptr); this.allocatedmem.push(blobptr); - this.db.handleError(sqlite3_bind_blob( + this.db["handleError"](sqlite3_bind_blob( this.stmt, pos, blobptr, @@ -581,7 +581,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { ? sqlite3_bind_int : sqlite3_bind_double ); - this.db.handleError(bindfunc(this.stmt, pos, num)); + this.db["handleError"](bindfunc(this.stmt, pos, num)); return true; }; @@ -769,7 +769,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { setValue(apiTemp, 0, "i32"); setValue(pzTail, 0, "i32"); try { - this.db.handleError(sqlite3_prepare_v2_sqlptr( + this.db["handleError"](sqlite3_prepare_v2_sqlptr( this.db.db, this.nextSqlPtr, -1, @@ -831,7 +831,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { if (data != null) { FS.createDataFile("/", this.filename, data, true, true); } - this.handleError(sqlite3_open(this.filename, apiTemp)); + this["handleError"](sqlite3_open(this.filename, apiTemp)); this.db = getValue(apiTemp, "i32"); registerExtensionFunctions(this.db); // A list of all prepared statements of the database @@ -869,7 +869,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { stmt["free"](); } } else { - this.handleError(sqlite3_exec(this.db, sql, 0, 0, apiTemp)); + this["handleError"](sqlite3_exec(this.db, sql, 0, 0, apiTemp)); } return this; }; @@ -957,7 +957,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { while (getValue(currentSqlPtr, "i8") !== NULL) { setValue(apiTemp, 0, "i32"); setValue(pzTail, 0, "i32"); - this.handleError(sqlite3_prepare_v2_sqlptr( + this["handleError"](sqlite3_prepare_v2_sqlptr( this.db, currentSqlPtr, -1, @@ -972,7 +972,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var curresult = null; stmt = new Statement(pStmt, this); if (params != null) { - stmt.bind(params); + stmt["bind"](params); } while (stmt["step"]()) { if (curresult === null) { @@ -1047,7 +1047,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { */ Database.prototype["prepare"] = function prepare(sql, params) { setValue(apiTemp, 0, "i32"); - this.handleError(sqlite3_prepare_v2(this.db, sql, -1, apiTemp, NULL)); + this["handleError"]( + sqlite3_prepare_v2(this.db, sql, -1, apiTemp, NULL) + ); // pointer to a statement, or null var pStmt = getValue(apiTemp, "i32"); if (pStmt === NULL) { @@ -1055,7 +1057,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { } var stmt = new Statement(pStmt, this); if (params != null) { - stmt.bind(params); + stmt["bind"](params); } this.statements[pStmt] = stmt; return stmt; @@ -1092,9 +1094,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { }); Object.values(this.functions).forEach(removeFunction); this.functions = {}; - this.handleError(sqlite3_close_v2(this.db)); + this["handleError"](sqlite3_close_v2(this.db)); var binaryDb = FS.readFile(this.filename, { encoding: "binary" }); - this.handleError(sqlite3_open(this.filename, apiTemp)); + this["handleError"](sqlite3_open(this.filename, apiTemp)); this.db = getValue(apiTemp, "i32"); registerExtensionFunctions(this.db); return binaryDb; @@ -1126,7 +1128,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { this.updateHookFunctionPtr = undefined; } - this.handleError(sqlite3_close_v2(this.db)); + this["handleError"](sqlite3_close_v2(this.db)); FS.unlink("/" + this.filename); this.db = null; }; @@ -1251,7 +1253,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { // void wrapped(sqlite3_context *db, int argc, sqlite3_value **argv) var func_ptr = addFunction(wrapped_func, "viii"); this.functions[name] = func_ptr; - this.handleError(sqlite3_create_function_v2( + this["handleError"](sqlite3_create_function_v2( this.db, name, func.length, @@ -1382,7 +1384,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { // > An aggregate SQL function requires an implementation of xStep and // > xFinal and NULL pointer must be passed for xFunc. // - http://www.sqlite.org/c3ref/create_function.html - this.handleError(sqlite3_create_function_v2( + this["handleError"](sqlite3_create_function_v2( this.db, name, step.length - 1, diff --git a/test/load_sql_lib.js b/test/load_sql_lib.js index f97848bb..06a2f101 100644 --- a/test/load_sql_lib.js +++ b/test/load_sql_lib.js @@ -1,9 +1,19 @@ module.exports = function(sqlLibraryType){ // Use sql-wasm.js by default var sqlJsLib = sqlLibraryType ? "../dist/sql-"+sqlLibraryType+".js" : "../dist/sql-wasm.js"; + var moduleConfig = {}; + if (sqlLibraryType && sqlLibraryType.indexOf("wasm-browser") === 0) { + var fs = require("fs"); + var path = require("path"); + var pathToFileURL = require("url").pathToFileURL; + moduleConfig.locateFile = function(filename){ + return pathToFileURL(path.resolve(__dirname, "../dist", filename)).href; + }; + moduleConfig.wasmBinary = fs.readFileSync(path.resolve(__dirname, "../dist/sql-wasm-browser.wasm")); + } begin = new Date(); var initSqlJs = require(sqlJsLib); - return initSqlJs().then((sql)=>{ + return initSqlJs(moduleConfig).then((sql)=>{ end = new Date(); console.log(`Loaded and inited ${sqlJsLib} in ${end -begin}ms`); return sql; diff --git a/test/test_worker.js b/test/test_worker.js index 42d11db4..8eaf1a9e 100644 --- a/test/test_worker.js +++ b/test/test_worker.js @@ -71,6 +71,11 @@ class SQLWorker { exports.test = async function test(SQL, assert) { var target = process.argv[2]; var file = target ? "sql-" + target : "sql-wasm"; + if (file.indexOf("wasm-browser") > -1) { + // Browser worker bundle expects web-style wasm loading; node worker_threads + // should exercise the node-compatible worker bundle instead. + file = "sql-wasm"; + } if (file.indexOf('memory-growth') > -1) { console.error("Skipping worker test for " + file + ". Not implemented yet"); return; From 177e44dc3b573b8f2643b03f99c4d313ead59e6a Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 4 Mar 2026 02:06:44 +0100 Subject: [PATCH 2/6] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 905116c0..8a9fe0ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sql.js", - "version": "1.14.0", + "version": "1.14.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sql.js", - "version": "1.14.0", + "version": "1.14.1", "license": "MIT", "devDependencies": { "@eslint/js": "^10.0.0", diff --git a/package.json b/package.json index 2da19a50..99ba61bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sql.js", - "version": "1.14.0", + "version": "1.14.1", "description": "SQLite library with support for opening and writing databases, prepared statements, and more. This SQLite library is in pure javascript (compiled with emscripten).", "keywords": [ "sql", From 882c48b9575a980946f2c839a41c8d3cc21b9b19 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 4 Mar 2026 02:11:33 +0100 Subject: [PATCH 3/6] undo docs changes --- src/api.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api.js b/src/api.js index 2e05a481..97c4001e 100644 --- a/src/api.js +++ b/src/api.js @@ -417,11 +417,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @example Print all the rows of the table test to the console var stmt = db.prepare("SELECT * FROM test"); - while (stmt["step"]()) console.log(stmt.get()); + while (stmt.step()) console.log(stmt.get()); Enable BigInt support var stmt = db.prepare("SELECT * FROM test"); - while (stmt["step"]()) console.log(stmt.get(null, {useBigInt: true})); + while (stmt.step()) console.log(stmt.get(null, {useBigInt: true})); */ Statement.prototype["get"] = function get(params, config) { config = config || {}; @@ -460,7 +460,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var stmt = db.prepare( "SELECT 5 AS nbr, x'616200' AS data, NULL AS null_value;" ); - stmt["step"](); // Execute the statement + stmt.step(); // Execute the statement console.log(stmt.getColumnNames()); // Will print ['nbr','data','null_value'] */ @@ -485,7 +485,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var stmt = db.prepare( "SELECT 5 AS nbr, x'010203' AS data, NULL AS null_value;" ); - stmt["step"](); // Execute the statement + stmt.step(); // Execute the statement console.log(stmt.getAsObject()); // Will print {nbr:5, data: Uint8Array([1,2,3]), null_value:null} */ From 4d4e9235ae765f05087fa4289f9d6d5b26dde5fd Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 4 Mar 2026 02:21:07 +0100 Subject: [PATCH 4/6] cleanup code with separate exports --- package.json | 3 +- src/api.js | 175 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 103 insertions(+), 75 deletions(-) diff --git a/package.json b/package.json index 99ba61bb..3bba4ac5 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "build": "make", "rebuild": "npm run clean && npm run build", "clean": "make clean", - "test": "npm run lint && npm run test-asm && npm run test-asm-debug && npm run test-wasm && npm run test-wasm-debug && npm run test-wasm-browser && npm run test-wasm-browser-debug && npm run test-asm-memory-growth", + "test": "npm run lint && npm run test-asm && npm run test-asm-debug && npm run test-wasm && npm run test-wasm-debug && npm run test-wasm-browser && npm run test-asm-memory-growth", "lint": "eslint .", "prettify": "eslint . --fix", "test-asm": "node --unhandled-rejections=strict test/all.js asm", @@ -38,7 +38,6 @@ "test-wasm": "node --unhandled-rejections=strict test/all.js wasm", "test-wasm-debug": "node --unhandled-rejections=strict test/all.js wasm-debug", "test-wasm-browser": "node --unhandled-rejections=strict test/all.js wasm-browser", - "test-wasm-browser-debug": "node --unhandled-rejections=strict test/all.js wasm-browser-debug", "doc": "jsdoc -c .jsdoc.config.json" }, "homepage": "http://github.com/sql-js/sql.js", diff --git a/src/api.js b/src/api.js index 97c4001e..fc2656d1 100644 --- a/src/api.js +++ b/src/api.js @@ -50,11 +50,11 @@ * @module SqlJs */ // Wait for preRun to run, and then finish our initialization -Module["onRuntimeInitialized"] = function onRuntimeInitialized() { +Module.onRuntimeInitialized = function onRuntimeInitialized() { // Declare toplevel variables // register, used for temporary stack values var apiTemp = stackAlloc(4); - var cwrap = Module["cwrap"]; + var cwrap = Module.cwrap; // Null pointer var NULL = 0; // SQLite enum @@ -327,11 +327,11 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { * @return {boolean} true if it worked * @throws {String} SQLite Error */ - Statement.prototype["bind"] = function bind(values) { + Statement.prototype.bind = function bind(values) { if (!this.stmt) { throw "Statement closed"; } - this["reset"](); + this.reset(); if (Array.isArray(values)) return this.bindFromArray(values); if (values != null && typeof values === "object") { return this.bindFromObject(values); @@ -345,7 +345,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @return {boolean} true if a row of result available @throws {String} SQLite Error */ - Statement.prototype["step"] = function step() { + Statement.prototype.step = function step() { if (!this.stmt) { throw "Statement closed"; } @@ -357,7 +357,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { case SQLITE_DONE: return false; default: - throw this.db["handleError"](ret); + throw this.db.handleError(ret); } }; @@ -423,17 +423,17 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var stmt = db.prepare("SELECT * FROM test"); while (stmt.step()) console.log(stmt.get(null, {useBigInt: true})); */ - Statement.prototype["get"] = function get(params, config) { + Statement.prototype.get = function get(params, config) { config = config || {}; - if (params != null && this["bind"](params)) { - this["step"](); + if (params != null && this.bind(params)) { + this.step(); } var results1 = []; var ref = sqlite3_data_count(this.stmt); for (var field = 0; field < ref; field += 1) { switch (sqlite3_column_type(this.stmt, field)) { case SQLITE_INTEGER: - var getfunc = config["useBigInt"] + var getfunc = config.useBigInt ? this.getBigInt(field) : this.getNumber(field); results1.push(getfunc); @@ -464,7 +464,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { console.log(stmt.getColumnNames()); // Will print ['nbr','data','null_value'] */ - Statement.prototype["getColumnNames"] = function getColumnNames() { + Statement.prototype.getColumnNames = function getColumnNames() { var results1 = []; var ref = sqlite3_column_count(this.stmt); for (var i = 0; i < ref; i += 1) { @@ -489,9 +489,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { console.log(stmt.getAsObject()); // Will print {nbr:5, data: Uint8Array([1,2,3]), null_value:null} */ - Statement.prototype["getAsObject"] = function getAsObject(params, config) { - var values = this["get"](params, config); - var names = this["getColumnNames"](); + Statement.prototype.getAsObject = function getAsObject(params, config) { + var values = this.get(params, config); + var names = this.getColumnNames(); var rowObject = {}; for (var i = 0; i < names.length; i += 1) { var name = names[i]; @@ -503,7 +503,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { /** Get the SQL string used in preparing this statement. @return {string} The SQL string */ - Statement.prototype["getSQL"] = function getSQL() { + Statement.prototype.getSQL = function getSQL() { return sqlite3_sql(this.stmt); }; @@ -519,7 +519,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @return {string} The normalized SQL string */ - Statement.prototype["getNormalizedSQL"] = function getNormalizedSQL() { + Statement.prototype.getNormalizedSQL = function getNormalizedSQL() { return sqlite3_normalized_sql(this.stmt); }; @@ -528,12 +528,12 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { and resets it @param {Statement.BindParams} [values] Value to bind to the statement */ - Statement.prototype["run"] = function run(values) { + Statement.prototype.run = function run(values) { if (values != null) { - this["bind"](values); + this.bind(values); } - this["step"](); - return this["reset"](); + this.step(); + return this.reset(); }; Statement.prototype.bindString = function bindString(string, pos) { @@ -543,7 +543,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { } var strptr = stringToNewUTF8(string); this.allocatedmem.push(strptr); - this.db["handleError"](sqlite3_bind_text( + this.db.handleError(sqlite3_bind_text( this.stmt, pos, strptr, @@ -561,7 +561,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var blobptr = _malloc(array.length); writeArrayToMemory(array, blobptr); this.allocatedmem.push(blobptr); - this.db["handleError"](sqlite3_bind_blob( + this.db.handleError(sqlite3_bind_blob( this.stmt, pos, blobptr, @@ -581,7 +581,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { ? sqlite3_bind_int : sqlite3_bind_double ); - this.db["handleError"](bindfunc(this.stmt, pos, num)); + this.db.handleError(bindfunc(this.stmt, pos, num)); return true; }; @@ -659,8 +659,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { It also clears all previous bindings, freeing the memory used by bound parameters. */ - Statement.prototype["reset"] = function reset() { - this["freemem"](); + Statement.prototype.reset = function reset() { + this.freemem(); return ( sqlite3_clear_bindings(this.stmt) === SQLITE_OK && sqlite3_reset(this.stmt) === SQLITE_OK @@ -668,7 +668,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { }; /** Free the memory allocated during parameter binding */ - Statement.prototype["freemem"] = function freemem() { + Statement.prototype.freemem = function freemem() { var mem; while ((mem = this.allocatedmem.pop()) !== undefined) { _free(mem); @@ -678,9 +678,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { /** Free the memory used by the statement @return {boolean} true in case of success */ - Statement.prototype["free"] = function free() { + Statement.prototype.free = function free() { var res; - this["freemem"](); + this.freemem(); res = sqlite3_finalize(this.stmt) === SQLITE_OK; delete this.db.statements[this.stmt]; this.stmt = NULL; @@ -752,12 +752,12 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @return {StatementIterator.StatementIteratorResult} @throws {String} SQLite error or invalid iterator error */ - StatementIterator.prototype["next"] = function next() { + StatementIterator.prototype.next = function next() { if (this.sqlPtr === null) { return { done: true }; } if (this.activeStatement !== null) { - this.activeStatement["free"](); + this.activeStatement.free(); this.activeStatement = null; } if (!this.db.db) { @@ -769,7 +769,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { setValue(apiTemp, 0, "i32"); setValue(pzTail, 0, "i32"); try { - this.db["handleError"](sqlite3_prepare_v2_sqlptr( + this.db.handleError(sqlite3_prepare_v2_sqlptr( this.db.db, this.nextSqlPtr, -1, @@ -802,7 +802,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { /** Get any un-executed portions remaining of the original SQL string @return {String} */ - StatementIterator.prototype["getRemainingSQL"] = function getRemainder() { + StatementIterator.prototype.getRemainingSQL = function getRemainder() { // iff an exception occurred, we set the nextSqlString if (this.nextSqlString !== null) return this.nextSqlString; // otherwise, convert from nextSqlPtr @@ -831,7 +831,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { if (data != null) { FS.createDataFile("/", this.filename, data, true, true); } - this["handleError"](sqlite3_open(this.filename, apiTemp)); + this.handleError(sqlite3_open(this.filename, apiTemp)); this.db = getValue(apiTemp, "i32"); registerExtensionFunctions(this.db); // A list of all prepared statements of the database @@ -857,19 +857,19 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @return {Database} The database object (useful for method chaining) */ - Database.prototype["run"] = function run(sql, params) { + Database.prototype.run = function run(sql, params) { if (!this.db) { throw "Database closed"; } if (params) { - var stmt = this["prepare"](sql, params); + var stmt = this.prepare(sql, params); try { - stmt["step"](); + stmt.step(); } finally { - stmt["free"](); + stmt.free(); } } else { - this["handleError"](sqlite3_exec(this.db, sql, 0, 0, apiTemp)); + this.handleError(sqlite3_exec(this.db, sql, 0, 0, apiTemp)); } return this; }; @@ -942,7 +942,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { (separated by `;`). This limitation does not apply to params as an object. * @return {Array} The results of each statement */ - Database.prototype["exec"] = function exec(sql, params, config) { + Database.prototype.exec = function exec(sql, params, config) { if (!this.db) { throw "Database closed"; } @@ -957,7 +957,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { while (getValue(currentSqlPtr, "i8") !== NULL) { setValue(apiTemp, 0, "i32"); setValue(pzTail, 0, "i32"); - this["handleError"](sqlite3_prepare_v2_sqlptr( + this.handleError(sqlite3_prepare_v2_sqlptr( this.db, currentSqlPtr, -1, @@ -972,24 +972,24 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { var curresult = null; stmt = new Statement(pStmt, this); if (params != null) { - stmt["bind"](params); + stmt.bind(params); } - while (stmt["step"]()) { + while (stmt.step()) { if (curresult === null) { curresult = { - columns: stmt["getColumnNames"](), - values: [], + "columns": stmt.getColumnNames(), + "values": [], }; results.push(curresult); } - curresult["values"].push(stmt["get"](null, config)); + curresult.values.push(stmt.get(null, config)); } - stmt["free"](); + stmt.free(); } } return results; } catch (errCaught) { - if (stmt) stmt["free"](); + if (stmt) stmt.free(); throw errCaught; } finally { if (originalSqlPtr) _free(originalSqlPtr); @@ -1017,20 +1017,20 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { ); */ // eslint-disable-next-line max-len - Database.prototype["each"] = function each(sql, params, callback, done, config) { + Database.prototype.each = function each(sql, params, callback, done, config) { var stmt; if (typeof params === "function") { done = callback; callback = params; params = undefined; } - stmt = this["prepare"](sql, params); + stmt = this.prepare(sql, params); try { - while (stmt["step"]()) { - callback(stmt["getAsObject"](null, config)); + while (stmt.step()) { + callback(stmt.getAsObject(null, config)); } } finally { - stmt["free"](); + stmt.free(); } if (typeof done === "function") { return done(); @@ -1045,9 +1045,9 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @return {Statement} the resulting statement @throws {String} SQLite error */ - Database.prototype["prepare"] = function prepare(sql, params) { + Database.prototype.prepare = function prepare(sql, params) { setValue(apiTemp, 0, "i32"); - this["handleError"]( + this.handleError( sqlite3_prepare_v2(this.db, sql, -1, apiTemp, NULL) ); // pointer to a statement, or null @@ -1057,7 +1057,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { } var stmt = new Statement(pStmt, this); if (params != null) { - stmt["bind"](params); + stmt.bind(params); } this.statements[pStmt] = stmt; return stmt; @@ -1079,7 +1079,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { * // 'SELECT 1 AS x;' { x: 1 } * // " SELECT '2' as y" { y: '2' } */ - Database.prototype["iterateStatements"] = function iterateStatements(sql) { + Database.prototype.iterateStatements = function iterateStatements(sql) { return new StatementIterator(sql, this); }; @@ -1088,15 +1088,15 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { * any pragmas to be set back to their default values. @return {Uint8Array} An array of bytes of the SQLite3 database file */ - Database.prototype["export"] = function exportDatabase() { + Database.prototype.export = function exportDatabase() { Object.values(this.statements).forEach(function each(stmt) { - stmt["free"](); + stmt.free(); }); Object.values(this.functions).forEach(removeFunction); this.functions = {}; - this["handleError"](sqlite3_close_v2(this.db)); + this.handleError(sqlite3_close_v2(this.db)); var binaryDb = FS.readFile(this.filename, { encoding: "binary" }); - this["handleError"](sqlite3_open(this.filename, apiTemp)); + this.handleError(sqlite3_open(this.filename, apiTemp)); this.db = getValue(apiTemp, "i32"); registerExtensionFunctions(this.db); return binaryDb; @@ -1112,13 +1112,13 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { * Databases **must** be closed when you're finished with them, or the * memory consumption will grow forever */ - Database.prototype["close"] = function close() { + Database.prototype.close = function close() { // do nothing if db is null or already closed if (this.db === null) { return; } Object.values(this.statements).forEach(function each(stmt) { - stmt["free"](); + stmt.free(); }); Object.values(this.functions).forEach(removeFunction); this.functions = {}; @@ -1128,7 +1128,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { this.updateHookFunctionPtr = undefined; } - this["handleError"](sqlite3_close_v2(this.db)); + this.handleError(sqlite3_close_v2(this.db)); FS.unlink("/" + this.filename); this.db = null; }; @@ -1137,7 +1137,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { an error with a descriptive message otherwise @nodoc */ - Database.prototype["handleError"] = function handleError(returnCode) { + Database.prototype.handleError = function handleError(returnCode) { var errmsg; if (returnCode === SQLITE_OK) { return null; @@ -1153,7 +1153,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @return {number} the number of rows modified */ - Database.prototype["getRowsModified"] = function getRowsModified() { + Database.prototype.getRowsModified = function getRowsModified() { return sqlite3_changes(this.db); }; @@ -1230,7 +1230,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @param {function(any)} func the actual function to be executed. @return {Database} The database object. Useful for method chaining */ - Database.prototype["create_function"] = function create_function( + Database.prototype.create_function = function create_function( name, func ) { @@ -1253,7 +1253,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { // void wrapped(sqlite3_context *db, int argc, sqlite3_value **argv) var func_ptr = addFunction(wrapped_func, "viii"); this.functions[name] = func_ptr; - this["handleError"](sqlite3_create_function_v2( + this.handleError(sqlite3_create_function_v2( this.db, name, func.length, @@ -1296,16 +1296,16 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { @return {Database} The database object. Useful for method chaining @template T */ - Database.prototype["create_aggregate"] = function create_aggregate( + Database.prototype.create_aggregate = function create_aggregate( name, aggregateFunctions ) { // Default initializer and finalizer - var init = aggregateFunctions["init"] + var init = aggregateFunctions.init || function init() { return null; }; - var finalize = aggregateFunctions["finalize"] + var finalize = aggregateFunctions.finalize || function finalize(state) { return state; }; - var step = aggregateFunctions["step"]; + var step = aggregateFunctions.step; if (!step) { throw "An aggregate function must have a step function in " + name; @@ -1384,7 +1384,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { // > An aggregate SQL function requires an implementation of xStep and // > xFinal and NULL pointer must be passed for xFunc. // - http://www.sqlite.org/c3ref/create_function.html - this["handleError"](sqlite3_create_function_v2( + this.handleError(sqlite3_create_function_v2( this.db, name, step.length - 1, @@ -1463,7 +1463,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { * - Set to `null` to unregister. * @returns {Database} The database object. Useful for method chaining */ - Database.prototype["updateHook"] = function updateHook(callback) { + Database.prototype.updateHook = function updateHook(callback) { if (this.updateHookFunctionPtr) { // unregister and cleanup a previously registered update hook sqlite3_update_hook(this.db, 0, 0); @@ -1535,6 +1535,35 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { * - The [rowid](https://www.sqlite.org/rowidtable.html) of the changed row */ + // Preserve public API names across minification. + Statement.prototype["bind"] = Statement.prototype.bind; + Statement.prototype["step"] = Statement.prototype.step; + Statement.prototype["get"] = Statement.prototype.get; + Statement.prototype["getColumnNames"] = Statement.prototype.getColumnNames; + Statement.prototype["getAsObject"] = Statement.prototype.getAsObject; + Statement.prototype["getSQL"] = Statement.prototype.getSQL; + Statement.prototype["getNormalizedSQL"] = Statement.prototype.getNormalizedSQL; + Statement.prototype["run"] = Statement.prototype.run; + Statement.prototype["reset"] = Statement.prototype.reset; + Statement.prototype["freemem"] = Statement.prototype.freemem; + Statement.prototype["free"] = Statement.prototype.free; + + StatementIterator.prototype["next"] = StatementIterator.prototype.next; + StatementIterator.prototype["getRemainingSQL"] = StatementIterator.prototype.getRemainingSQL; + + Database.prototype["run"] = Database.prototype.run; + Database.prototype["exec"] = Database.prototype.exec; + Database.prototype["each"] = Database.prototype.each; + Database.prototype["prepare"] = Database.prototype.prepare; + Database.prototype["iterateStatements"] = Database.prototype.iterateStatements; + Database.prototype["export"] = Database.prototype.export; + Database.prototype["close"] = Database.prototype.close; + Database.prototype["handleError"] = Database.prototype.handleError; + Database.prototype["getRowsModified"] = Database.prototype.getRowsModified; + Database.prototype["create_function"] = Database.prototype.create_function; + Database.prototype["create_aggregate"] = Database.prototype.create_aggregate; + Database.prototype["updateHook"] = Database.prototype.updateHook; + // export Database to Module Module.Database = Database; }; From a84969d4048aa3f44b1042bf8521feb069adc948 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 4 Mar 2026 02:24:05 +0100 Subject: [PATCH 5/6] eslint --- src/api.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/api.js b/src/api.js index fc2656d1..4f4130b5 100644 --- a/src/api.js +++ b/src/api.js @@ -1536,33 +1536,40 @@ Module.onRuntimeInitialized = function onRuntimeInitialized() { */ // Preserve public API names across minification. + /* eslint-disable no-self-assign */ Statement.prototype["bind"] = Statement.prototype.bind; Statement.prototype["step"] = Statement.prototype.step; Statement.prototype["get"] = Statement.prototype.get; - Statement.prototype["getColumnNames"] = Statement.prototype.getColumnNames; + Statement.prototype["getColumnNames"] + = Statement.prototype.getColumnNames; Statement.prototype["getAsObject"] = Statement.prototype.getAsObject; Statement.prototype["getSQL"] = Statement.prototype.getSQL; - Statement.prototype["getNormalizedSQL"] = Statement.prototype.getNormalizedSQL; + Statement.prototype["getNormalizedSQL"] + = Statement.prototype.getNormalizedSQL; Statement.prototype["run"] = Statement.prototype.run; Statement.prototype["reset"] = Statement.prototype.reset; Statement.prototype["freemem"] = Statement.prototype.freemem; Statement.prototype["free"] = Statement.prototype.free; StatementIterator.prototype["next"] = StatementIterator.prototype.next; - StatementIterator.prototype["getRemainingSQL"] = StatementIterator.prototype.getRemainingSQL; + StatementIterator.prototype["getRemainingSQL"] + = StatementIterator.prototype.getRemainingSQL; Database.prototype["run"] = Database.prototype.run; Database.prototype["exec"] = Database.prototype.exec; Database.prototype["each"] = Database.prototype.each; Database.prototype["prepare"] = Database.prototype.prepare; - Database.prototype["iterateStatements"] = Database.prototype.iterateStatements; + Database.prototype["iterateStatements"] + = Database.prototype.iterateStatements; Database.prototype["export"] = Database.prototype.export; Database.prototype["close"] = Database.prototype.close; Database.prototype["handleError"] = Database.prototype.handleError; Database.prototype["getRowsModified"] = Database.prototype.getRowsModified; Database.prototype["create_function"] = Database.prototype.create_function; - Database.prototype["create_aggregate"] = Database.prototype.create_aggregate; + Database.prototype["create_aggregate"] + = Database.prototype.create_aggregate; Database.prototype["updateHook"] = Database.prototype.updateHook; + /* eslint-enable no-self-assign */ // export Database to Module Module.Database = Database; From cd145303c67123339cb3c6386baee3054b5f5a5f Mon Sep 17 00:00:00 2001 From: lovasoa Date: Wed, 4 Mar 2026 02:40:18 +0100 Subject: [PATCH 6/6] fix minimifaction issues --- src/api.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/api.js b/src/api.js index 4f4130b5..829f2bfe 100644 --- a/src/api.js +++ b/src/api.js @@ -50,11 +50,11 @@ * @module SqlJs */ // Wait for preRun to run, and then finish our initialization -Module.onRuntimeInitialized = function onRuntimeInitialized() { +Module["onRuntimeInitialized"] = function onRuntimeInitialized() { // Declare toplevel variables // register, used for temporary stack values var apiTemp = stackAlloc(4); - var cwrap = Module.cwrap; + var cwrap = Module["cwrap"]; // Null pointer var NULL = 0; // SQLite enum @@ -433,7 +433,7 @@ Module.onRuntimeInitialized = function onRuntimeInitialized() { for (var field = 0; field < ref; field += 1) { switch (sqlite3_column_type(this.stmt, field)) { case SQLITE_INTEGER: - var getfunc = config.useBigInt + var getfunc = config["useBigInt"] ? this.getBigInt(field) : this.getNumber(field); results1.push(getfunc); @@ -1301,11 +1301,11 @@ Module.onRuntimeInitialized = function onRuntimeInitialized() { aggregateFunctions ) { // Default initializer and finalizer - var init = aggregateFunctions.init + var init = aggregateFunctions["init"] || function init() { return null; }; - var finalize = aggregateFunctions.finalize + var finalize = aggregateFunctions["finalize"] || function finalize(state) { return state; }; - var step = aggregateFunctions.step; + var step = aggregateFunctions["step"]; if (!step) { throw "An aggregate function must have a step function in " + name; @@ -1572,5 +1572,5 @@ Module.onRuntimeInitialized = function onRuntimeInitialized() { /* eslint-enable no-self-assign */ // export Database to Module - Module.Database = Database; + Module["Database"] = Database; };