jsql-neo 6.7.1 → 6.7.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/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.1** — stable release · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
6
+ > **v6.7.2** — 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)
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * JSQL-NEO v6.7.1 — Rust-Powered Embedded Database (WASM + HTTP)
2
+ * JSQL-NEO v6.7.2 — Rust-Powered Embedded Database (WASM + HTTP)
3
3
  *
4
4
  * @example
5
5
  * const jsql = require('jsql-neo');
package/lib/sql.js CHANGED
@@ -2705,6 +2705,32 @@ class Parser {
2705
2705
  this.expect('op', ')');
2706
2706
  return { type: 'cast', expr, dataType };
2707
2707
  }
2708
+ // CONVERT(expr, type) —— MySQL 的另一种 CAST 写法,语义与 CAST 完全一致,
2709
+ // 直接复用 cast 节点。此前完全没解析,SIGNED / CHAR 被当成列名,
2710
+ // 报 "no such column: SIGNED"。
2711
+ // `CONVERT(expr USING charset)` 是另一套语法,这里不支持(会报语法错,
2712
+ // 比静默当成列引用好)。
2713
+ if (String(t.value).toUpperCase() === 'CONVERT' && this.peek().type === 'op' && this.peek().value === '(') {
2714
+ this.next();
2715
+ const expr = this.parseScalar();
2716
+ this.expect('op', ',');
2717
+ const typeTok = this.next();
2718
+ let dataType = String(typeTok.value).toUpperCase();
2719
+ if (this.peek().type === 'op' && this.peek().value === '(') {
2720
+ this.next();
2721
+ let depth = 1;
2722
+ let spec = '';
2723
+ while (depth > 0 && this.peek().type !== 'eof') {
2724
+ const tk = this.next();
2725
+ if (tk.type === 'op' && tk.value === '(') depth++;
2726
+ else if (tk.type === 'op' && tk.value === ')') { depth--; if (depth === 0) break; }
2727
+ spec += tk.value;
2728
+ }
2729
+ dataType += '(' + spec + ')';
2730
+ }
2731
+ this.expect('op', ')');
2732
+ return { type: 'cast', expr, dataType };
2733
+ }
2708
2734
  // 零参时间函数:CURRENT_DATE / CURRENT_TIME / CURRENT_TIMESTAMP(可省略括号)。
2709
2735
  // 此前不在 KEYWORDS 里,被当成列名解析 → "no such column: CURRENT_DATE"
2710
2736
  if (['CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP'].includes(String(t.value).toUpperCase())) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo",
3
- "version": "6.7.1",
3
+ "version": "6.7.2",
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 && node test/cast-rounding.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 && node test/convert-subquery.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 && node test/cast-rounding.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 && node test/convert-subquery.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,88 @@
1
+ /* ---- CONVERT / BINARY / GROUP_CONCAT / HAVING / IN 子查询的 NULL 语义 ---- */
2
+ /*
3
+ * 这一轮差分探针(16 条)只错 2 条,都是 `CONVERT(expr, type)` 没被解析
4
+ * (报 no such column: SIGNED)—— 功能缺失,不是静默错值。补上后连同
5
+ * 同批验证过、但此前没有回归覆盖的边界一起钉住。
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
+ await db.createTable('t', {
20
+ id: { type: 'integer', primaryKey: true, autoIncrement: true },
21
+ g: { type: 'string' }, v: { type: 'integer' },
22
+ });
23
+ await db.insert('t', [{ g: 'a', v: 1 }, { g: 'a', v: 2 }, { g: 'b', v: 3 }]);
24
+ await db.createTable('s', {
25
+ id: { type: 'integer', primaryKey: true, autoIncrement: true }, v: { type: 'integer' },
26
+ });
27
+ await db.insert('s', [{ v: 1 }, { v: null }]);
28
+ await db.createTable('empty', {
29
+ id: { type: 'integer', primaryKey: true, autoIncrement: true }, v: { type: 'integer' },
30
+ });
31
+
32
+ const q = async (sql) => (await executeSQL(db, sql, { safety: false })).rows[0][0];
33
+
34
+ // ---------- CONVERT(expr, type):与 CAST 语义一致 ----------
35
+ ok("CONVERT('12abc', SIGNED) = 12", await q("SELECT CONVERT('12abc', SIGNED)") === 12, null);
36
+ ok('CONVERT(42, CHAR) = "42"', await q('SELECT CONVERT(42, CHAR)') === '42', null);
37
+ ok('CONVERT(1.9, SIGNED) = 2(四舍五入)', await q('SELECT CONVERT(1.9, SIGNED)') === 2, null);
38
+ ok('CONVERT(12.9, INTEGER) = 13', await q('SELECT CONVERT(12.9, INTEGER)') === 13, null);
39
+ ok("CONVERT('3.14159', DECIMAL(10,2)) = 3.14",
40
+ await q("SELECT CONVERT('3.14159', DECIMAL(10,2))") === 3.14, null);
41
+ ok('CONVERT(NULL, SIGNED) = NULL', await q('SELECT CONVERT(NULL, SIGNED)') === null, null);
42
+ ok('CONVERT(-5, UNSIGNED) 按 2^64 回绕',
43
+ String(await q('SELECT CONVERT(-5, UNSIGNED)')) === '18446744073709551611', null);
44
+ ok('CONVERT 与 CAST 结果一致',
45
+ await q('SELECT CONVERT(12.9, SIGNED)') === await q('SELECT CAST(12.9 AS SIGNED)'), null);
46
+
47
+ // ---------- BINARY:大小写敏感 ----------
48
+ ok("BINARY g = 'A' 不命中小写 'a'",
49
+ await q("SELECT COUNT(*) AS c FROM t WHERE BINARY g = 'A'") === 0, null);
50
+ ok("默认 collation 下 g = 'A' 命中 'a'(CI)",
51
+ await q("SELECT COUNT(*) AS c FROM t WHERE g = 'A'") === 2, null);
52
+
53
+ // ---------- GROUP_CONCAT ----------
54
+ ok('GROUP_CONCAT 默认逗号', await q('SELECT GROUP_CONCAT(v) AS x FROM t') === '1,2,3', null);
55
+ ok("GROUP_CONCAT SEPARATOR '|'",
56
+ await q("SELECT GROUP_CONCAT(v SEPARATOR '|') AS x FROM t") === '1|2|3', null);
57
+ ok('GROUP_CONCAT ORDER BY DESC',
58
+ await q('SELECT GROUP_CONCAT(v ORDER BY v DESC) AS x FROM t') === '3,2,1', null);
59
+ ok('GROUP_CONCAT DISTINCT', await q('SELECT GROUP_CONCAT(DISTINCT g) AS x FROM t') === 'a,b', null);
60
+
61
+ // ---------- HAVING:表达式与别名等价 ----------
62
+ const h1 = JSON.stringify((await executeSQL(db, 'SELECT g, SUM(v) AS s FROM t GROUP BY g HAVING SUM(v) > 2', { safety: false })).rows);
63
+ const h2 = JSON.stringify((await executeSQL(db, 'SELECT g, SUM(v) AS s FROM t GROUP BY g HAVING s > 2', { safety: false })).rows);
64
+ ok('HAVING 聚合表达式', h1 === '[["a",3],["b",3]]', h1);
65
+ ok('HAVING 用别名与表达式结果一致', h1 === h2, { h1, h2 });
66
+
67
+ // ---------- IN / NOT IN 子查询的三值逻辑 ----------
68
+ ok('IN 子查询命中', await q('SELECT COUNT(*) AS c FROM t WHERE v IN (SELECT v FROM s)') === 1, null);
69
+ // 关键:子查询含 NULL 时,NOT IN 对任何行都不成立(结果集为空)
70
+ ok('NOT IN 含 NULL → 0 行(三值逻辑)',
71
+ await q('SELECT COUNT(*) AS c FROM t WHERE v NOT IN (SELECT v FROM s)') === 0, null);
72
+ ok('IN 空子查询 → 0 行',
73
+ await q('SELECT COUNT(*) AS c FROM t WHERE v IN (SELECT v FROM empty)') === 0, null);
74
+ ok('NOT IN 空子查询 → 全部行',
75
+ await q('SELECT COUNT(*) AS c FROM t WHERE v NOT IN (SELECT v FROM empty)') === 3, null);
76
+
77
+ // ---------- EXISTS / NOT EXISTS ----------
78
+ ok('EXISTS 相关子查询',
79
+ await q('SELECT COUNT(*) AS c FROM t WHERE EXISTS (SELECT 1 FROM s WHERE s.v = t.v)') === 1, null);
80
+ ok('NOT EXISTS 相关子查询',
81
+ await q('SELECT COUNT(*) AS c FROM t WHERE NOT EXISTS (SELECT 1 FROM s WHERE s.v = t.v)') === 2, null);
82
+
83
+ console.log(`\n${pass} passed, ${fail} failed`);
84
+ process.exit(fail === 0 ? 0 : 1);
85
+ })().catch(e => {
86
+ console.log('[FAIL] unexpected exception: ' + e.stack.split('\n').slice(0, 3).join('\n'));
87
+ process.exit(1);
88
+ });