jsql-neo 6.7.0-beta.5 → 6.7.1

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > **One engine to rule them all** — a Rust-powered embedded database that speaks your language:
4
4
  > MySQL, PostgreSQL, MongoDB, Redis, SQL, TypeScript, **and the browser**.
5
5
 
6
- > **v6.7.0-beta.5** — beta release · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
6
+ > **v6.7.1** — stable release · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
7
7
 
8
8
  ![Engines](https://img.shields.io/badge/engines-Native%20%7C%20WASM%20%7C%20Pure%20JS-7ee787)
9
9
  ![MySQL](https://img.shields.io/badge/protocol-MySQL%20compatible-1f6feb)
@@ -222,8 +222,9 @@ A **derived in-memory view**, not an on-disk format: any write invalidates it
222
222
  single-column `GROUP BY` scan the column arrays directly (no row objects).
223
223
 
224
224
  Point queries measure **2.7–6.5x faster than DuckDB**; aggregation is now
225
- **2–8x slower** (it was 36–70x before the vectorized column path). Still behind —
226
- not claimed otherwise. Honest numbers: [doc/columnar.md](doc/columnar.md).
225
+ **2–6x slower** (it was 36–70x before the vectorized column path). Still behind —
226
+ not claimed otherwise. `JOIN`-then-aggregate is **not** optimized yet and falls
227
+ back to the row path. Honest numbers and limits: [doc/columnar.md](doc/columnar.md).
227
228
 
228
229
  ## ✨ XQL 集成
229
230
 
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * JSQL-NEO v6.7.0-beta.5 — Rust-Powered Embedded Database (WASM + HTTP)
2
+ * JSQL-NEO v6.7.1 — Rust-Powered Embedded Database (WASM + HTTP)
3
3
  *
4
4
  * @example
5
5
  * const jsql = require('jsql-neo');
package/lib/sql.js CHANGED
@@ -3252,12 +3252,17 @@ function applyCast(value, dataType) {
3252
3252
  if (t === 'INTEGER' || t === 'INT' || t === 'BIGINT' || t === 'SMALLINT' ||
3253
3253
  t === 'TINYINT' || t === 'SIGNED' || t === 'MEDIUMINT' || t === 'UNSIGNED') {
3254
3254
  // MySQL CAST(... AS SIGNED/INT):取数字前缀('12abc'→12),无法解析时返回 0(而非 null)。
3255
+ // MySQL 的 CAST(x AS SIGNED/INT) 对小数是**四舍五入**(半远离零),
3256
+ // 不是截断:CAST(1.9 AS SIGNED) = 2、CAST(-1.5 AS SIGNED) = -2。
3257
+ // 此前用 Math.trunc,1.9 会得到 1。Math.round 是「半向 +∞」,
3258
+ // 负数要先取绝对值再舍入,否则 -1.5 会变成 -1。
3259
+ const roundHalfAway = (x) => (x < 0 ? -Math.round(-x) : Math.round(x));
3255
3260
  let n;
3256
3261
  if (typeof value === 'boolean') n = value ? 1 : 0;
3257
- else if (typeof value === 'number') n = Number.isFinite(value) ? Math.trunc(value) : 0;
3262
+ else if (typeof value === 'number') n = Number.isFinite(value) ? roundHalfAway(value) : 0;
3258
3263
  else {
3259
3264
  const m = String(value).trim().match(/^[+-]?\d+(\.\d+)?/);
3260
- n = m ? Math.trunc(Number(m[0])) : 0;
3265
+ n = m ? roundHalfAway(Number(m[0])) : 0;
3261
3266
  }
3262
3267
  // CAST(... AS UNSIGNED) 是 BIGINT UNSIGNED:负数按 2^64 回绕,
3263
3268
  // 而不是原样保留负号。CAST(-5 AS UNSIGNED) 应为 18446744073709551611。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo",
3
- "version": "6.7.0-beta.5",
3
+ "version": "6.7.1",
4
4
  "description": "JSQL-NEO — Rust-powered embedded database with WASM, REST API, B-Tree indexes, WAL, crash recovery",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -52,12 +52,12 @@
52
52
  "build:native": "node scripts/build-native.js",
53
53
  "check:release": "node scripts/check-release-metadata.js",
54
54
  "release:prep": "node scripts/release.js",
55
- "test": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/native.test.js && node test/json-functions.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/query-opt.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/dml-constraints.test.js && node test/star-nag.test.js && node test/plugin-xql.test.js && node test/bug-regression-2.test.js && node test/issue-34-35-36.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-73-76.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js",
55
+ "test": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/native.test.js && node test/json-functions.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/query-opt.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/dml-constraints.test.js && node test/star-nag.test.js && node test/plugin-xql.test.js && node test/bug-regression-2.test.js && node test/issue-34-35-36.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-73-76.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js",
56
56
  "test:parser": "node test/sql-parser.test.js",
57
57
  "test:btree": "node test/btree.test.js",
58
58
  "test:native": "node test/native.test.js",
59
59
  "test:regress": "node test/regress-5.1.0.js",
60
- "test:all": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/native.test.js && node test/native-multi-instance.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/wasm.test.js && node test/coverage.js && node test/regress-5.1.0.js && node test/join.test.js && node test/btree.test.js && node test/dml-constraints.test.js && node test/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.test.js && node test/issue-34-35-36.test.js && node test/sql-semantics.test.js && node test/extra-coverage.test.js && node test/filter-compile.test.js && node test/recursive-cte.test.js && node test/index-ddl.test.js && node test/mongo-group.test.js && node test/multiprotocol.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js",
60
+ "test:all": "npm run check:release && node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/native.test.js && node test/native-multi-instance.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/wasm.test.js && node test/coverage.js && node test/regress-5.1.0.js && node test/join.test.js && node test/btree.test.js && node test/dml-constraints.test.js && node test/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.test.js && node test/issue-34-35-36.test.js && node test/sql-semantics.test.js && node test/extra-coverage.test.js && node test/filter-compile.test.js && node test/recursive-cte.test.js && node test/index-ddl.test.js && node test/mongo-group.test.js && node test/multiprotocol.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-77-84.test.js && node test/issue-86-99.test.js && node test/issue-101-103.test.js && node test/issue-105.test.js && node test/bigint-math.test.js && node test/release-metadata.test.js && node test/date-conversions.test.js && node test/mysql-utility-functions.test.js && node test/limit-pushdown.test.js && node test/columnar.test.js && node test/columnar-vector.test.js && node test/cast-rounding.test.js",
61
61
  "test:coverage": "c8 --all --include='lib/**' --exclude='lib/web_ui.js' --reporter=text --reporter=lcov node test/coverage.js",
62
62
  "test:orms": "node examples/orms/run-all.js",
63
63
  "test:dml": "node test/dml-constraints.test.js",
@@ -0,0 +1,56 @@
1
+ /* ---- CAST 到整数:MySQL 是四舍五入,不是截断 ---- */
2
+ /*
3
+ * 差分探针发现 `CAST(1.9 AS SIGNED)` 返回 1,MySQL 8.0 返回 2 —— 小数转
4
+ * 整数是 **四舍五入(半远离零)**,不是截断。此前用 Math.trunc。
5
+ * 注意 Math.round 是「半向 +∞」,负数必须取绝对值再舍入,否则 -1.5 → -1。
6
+ */
7
+ const path = require('path');
8
+ const ROOT = path.join(__dirname, '..');
9
+ const { Database, executeSQL } = require(path.join(ROOT, 'index.js'));
10
+
11
+ let pass = 0, fail = 0;
12
+ function ok(name, cond, got) {
13
+ if (cond) { pass++; console.log('[OK] ' + name); }
14
+ else { fail++; console.log('[FAIL] ' + name + ' -> ' + JSON.stringify(got)); }
15
+ }
16
+
17
+ (async () => {
18
+ const db = new Database(':memory:', { autoSave: false });
19
+ const q = async (sql) => (await executeSQL(db, sql, { safety: false })).rows[0][0];
20
+
21
+ // ---------- 正数:四舍五入 ----------
22
+ ok('CAST(1.4 AS SIGNED) = 1', await q('SELECT CAST(1.4 AS SIGNED)') === 1, null);
23
+ ok('CAST(1.5 AS SIGNED) = 2(半远离零)', await q('SELECT CAST(1.5 AS SIGNED)') === 2, null);
24
+ ok('CAST(1.9 AS SIGNED) = 2(此前错为 1)', await q('SELECT CAST(1.9 AS SIGNED)') === 2, null);
25
+ ok('CAST(2.5 AS SIGNED) = 3', await q('SELECT CAST(2.5 AS SIGNED)') === 3, null);
26
+ ok('CAST(2.4 AS SIGNED) = 2', await q('SELECT CAST(2.4 AS SIGNED)') === 2, null);
27
+
28
+ // ---------- 负数:不能变成「半向 +∞」 ----------
29
+ ok('CAST(-1.4 AS SIGNED) = -1', await q('SELECT CAST(-1.4 AS SIGNED)') === -1, null);
30
+ ok('CAST(-1.5 AS SIGNED) = -2(半远离零)', await q('SELECT CAST(-1.5 AS SIGNED)') === -2, null);
31
+ ok('CAST(-1.9 AS SIGNED) = -2', await q('SELECT CAST(-1.9 AS SIGNED)') === -2, null);
32
+
33
+ // ---------- 字符串 ----------
34
+ ok("CAST('1.9' AS SIGNED) = 2", await q("SELECT CAST('1.9' AS SIGNED)") === 2, null);
35
+ ok("CAST('12abc' AS SIGNED) = 12(取数字前缀)", await q("SELECT CAST('12abc' AS SIGNED)") === 12, null);
36
+ ok("CAST('abc' AS SIGNED) = 0", await q("SELECT CAST('abc' AS SIGNED)") === 0, null);
37
+ ok("CAST('-1.5' AS SIGNED) = -2", await q("SELECT CAST('-1.5' AS SIGNED)") === -2, null);
38
+
39
+ // ---------- UNSIGNED / NULL ----------
40
+ ok('CAST(2.5 AS UNSIGNED) = 3', await q('SELECT CAST(2.5 AS UNSIGNED)') === 3, null);
41
+ ok('CAST(-5 AS UNSIGNED) 按 2^64 回绕',
42
+ String(await q('SELECT CAST(-5 AS UNSIGNED)')) === '18446744073709551611', null);
43
+ ok('CAST(NULL AS SIGNED) = NULL', await q('SELECT CAST(NULL AS SIGNED)') === null, null);
44
+
45
+ // ---------- 不回归:DECIMAL 标度(#96)与其它类型 ----------
46
+ ok('CAST(123.456 AS DECIMAL(10,2)) = 123.46',
47
+ await q('SELECT CAST(123.456 AS DECIMAL(10,2))') === 123.46, null);
48
+ ok('CAST(1.9 AS CHAR) 仍是字符串', await q('SELECT CAST(1.9 AS CHAR)') === '1.9', null);
49
+ ok('CAST(42 AS CHAR) 仍是字符串', await q('SELECT CAST(42 AS CHAR)') === '42', null);
50
+
51
+ console.log(`\n${pass} passed, ${fail} failed`);
52
+ process.exit(fail === 0 ? 0 : 1);
53
+ })().catch(e => {
54
+ console.log('[FAIL] unexpected exception: ' + e.stack.split('\n').slice(0, 3).join('\n'));
55
+ process.exit(1);
56
+ });
@@ -521,7 +521,8 @@ const rowsOf = (r) => (Array.isArray(r) ? r[0] : r).rows;
521
521
  // CAST(x AS INT):数字前缀解析、非法为 0(此前返回 null)
522
522
  ok("CAST('abc' AS INT) → 0", await scalar("SELECT CAST('abc' AS INT) AS x") === 0);
523
523
  ok("CAST('12abc' AS INT) → 12", await scalar("SELECT CAST('12abc' AS INT) AS x") === 12);
524
- ok("CAST('3.9' AS INT) → 3", await scalar("SELECT CAST('3.9' AS INT) AS x") === 3);
524
+ // MySQL 8.0:小数转整数是四舍五入(半远离零),不是截断 → 3.9 应为 4
525
+ ok("CAST('3.9' AS INT) → 4", await scalar("SELECT CAST('3.9' AS INT) AS x") === 4);
525
526
  // ROUND 中点浮点偏差
526
527
  ok('ROUND(1.005, 2) → 1.01', await scalar('SELECT ROUND(1.005, 2) AS x') === 1.01);
527
528
  ok('ROUND(2.5, 0) → 3(半远离零)', await scalar('SELECT ROUND(2.5, 0) AS x') === 3);
@@ -735,8 +736,9 @@ const rowsOf = (r) => (Array.isArray(r) ? r[0] : r).rows;
735
736
  const cast = [
736
737
  [`SELECT CAST('12abc' AS SIGNED) AS v`, 12, 'SIGNED 取数字前缀'],
737
738
  [`SELECT CAST('abc' AS SIGNED) AS v`, 0, 'SIGNED 非数字返 0'],
738
- [`SELECT CAST(12.9 AS SIGNED) AS v`, 12, 'SIGNED 截断小数'],
739
- [`SELECT CAST(12.9 AS INTEGER) AS v`, 12, 'INTEGER 回归对照'],
739
+ // 小数按 MySQL 语义四舍五入(此前实现与这两条断言都写成了截断,已修正)
740
+ [`SELECT CAST(12.9 AS SIGNED) AS v`, 13, 'SIGNED 四舍五入小数'],
741
+ [`SELECT CAST(12.9 AS INTEGER) AS v`, 13, 'INTEGER 与 SIGNED 一致'],
740
742
  ];
741
743
  for (const [sql, expect, desc] of cast) {
742
744
  let got = null, err = null;