jsql-neo 6.8.22 → 6.8.23
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 +1 -1
- package/index.js +1 -1
- package/lib/errors.js +1 -0
- package/lib/sql.js +31 -2
- package/lib/tui.js +8 -1
- package/package.json +3 -3
- package/test/issue-258-300.test.js +64 -0
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.8.
|
|
6
|
+
> **v6.8.23** — 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
|

|
|
9
9
|

|
package/index.js
CHANGED
package/lib/errors.js
CHANGED
|
@@ -57,6 +57,7 @@ const ErrorCodes = {
|
|
|
57
57
|
// 保存点不存在(MySQL 用这个码:SAVEPOINT xxx does not exist)
|
|
58
58
|
ER_SP_DOES_NOT_EXIST: { code: 1305, msg: "SAVEPOINT %s does not exist" },
|
|
59
59
|
ER_FUNCTION_NOT_EXIST: { code: 1305, msg: "FUNCTION %s does not exist" },
|
|
60
|
+
ER_SUBSELECT_NO_1_ROW: { code: 1242, msg: "Subquery returns more than 1 row" },
|
|
60
61
|
ER_WRONG_VALUE_COUNT_ON_ROW: { code: 1136, msg: "Column count doesn't match value count at row %s" },
|
|
61
62
|
ER_TRUNCATE_ILLEGAL_FK: { code: 1701, msg: "Cannot truncate a table referenced in a foreign key constraint (%s)" },
|
|
62
63
|
ER_ROW_IS_REFERENCED_2: { code: 1451, msg: "Cannot delete or update a parent row: a foreign key constraint fails (%s)" },
|
package/lib/sql.js
CHANGED
|
@@ -529,7 +529,7 @@ function tokenize(sql) {
|
|
|
529
529
|
const AGG_FUNCS = new Set(['SUM', 'AVG', 'MIN', 'MAX', 'COUNT',
|
|
530
530
|
'GROUP_CONCAT', 'STDDEV', 'STD', 'STDDEV_POP', 'STDDEV_SAMP',
|
|
531
531
|
'VARIANCE', 'VAR_POP', 'VAR_SAMP', 'FIRST', 'LAST',
|
|
532
|
-
'BIT_AND', 'BIT_OR', 'BIT_XOR']);
|
|
532
|
+
'BIT_AND', 'BIT_OR', 'BIT_XOR', 'JSON_ARRAYAGG', 'JSON_OBJECTAGG']);
|
|
533
533
|
|
|
534
534
|
// 方差/标准差族(Issue #114):MySQL 里无后缀的 VARIANCE / STDDEV / STD
|
|
535
535
|
// 都是**总体**口径(= VAR_POP / STDDEV_POP),不是样本。
|
|
@@ -2660,7 +2660,15 @@ class Parser {
|
|
|
2660
2660
|
}
|
|
2661
2661
|
column = { type: 'tuple', items: cols };
|
|
2662
2662
|
} else if (this.peek().type === 'op' && this.peek().value === ',') {
|
|
2663
|
-
if (
|
|
2663
|
+
if (fn === 'JSON_OBJECTAGG') {
|
|
2664
|
+
// JSON_OBJECTAGG(key, value):收集 [key, value] 两个表达式
|
|
2665
|
+
const items = [column];
|
|
2666
|
+
while (this.peek().type === 'op' && this.peek().value === ',') {
|
|
2667
|
+
this.next();
|
|
2668
|
+
items.push(this.parseScalar());
|
|
2669
|
+
}
|
|
2670
|
+
column = { type: 'arglist', items };
|
|
2671
|
+
} else if (VARIANCE_FUNCS.has(fn)) {
|
|
2664
2672
|
// Issue #114:MySQL 的 VARIANCE/STDDEV/STD 只接受单个表达式,
|
|
2665
2673
|
// 但本项目历史上接受 VARIANCE(1,2,3) 这种多参数写法,统一收集成 arglist,
|
|
2666
2674
|
// 让每个参数值都参与统计(多参数时不再误当成 GROUP_CONCAT 的分隔符)。
|
|
@@ -8200,6 +8208,8 @@ class SQLExecutor {
|
|
|
8200
8208
|
}
|
|
8201
8209
|
if (expr.type === 'subquery') {
|
|
8202
8210
|
const res = await this.executeSelect(expr.select);
|
|
8211
|
+
// #258:标量子查询返回多行必须报 1242,不能静默取首行
|
|
8212
|
+
if (res.rows.length > 1) throw createError('ER_SUBSELECT_NO_1_ROW');
|
|
8203
8213
|
expr._value = res.rows.length > 0 ? res.rows[0][0] : null;
|
|
8204
8214
|
// 不改写类型、不 delete select:保留节点以便相关场景逐行重算
|
|
8205
8215
|
return;
|
|
@@ -8305,6 +8315,24 @@ class SQLExecutor {
|
|
|
8305
8315
|
const op = typeof column === 'string' ? { type: 'column', name: column } : column;
|
|
8306
8316
|
// COUNT(*) / COUNT():参数为 star 或缺失,直接按行数算
|
|
8307
8317
|
const noColumn = !op || op.type === 'star';
|
|
8318
|
+
// #293:JSON 聚合按整组求值,不能退化成每组取代表行
|
|
8319
|
+
if (fn === 'JSON_ARRAYAGG') {
|
|
8320
|
+
const out = rows.map(r => resolveOperand(op, r, this.ctx));
|
|
8321
|
+
return out;
|
|
8322
|
+
}
|
|
8323
|
+
if (fn === 'JSON_OBJECTAGG') {
|
|
8324
|
+
const obj = {};
|
|
8325
|
+
const items = op && op.type === 'arglist' ? op.items : [];
|
|
8326
|
+
if (items.length >= 2) {
|
|
8327
|
+
for (const r of rows) {
|
|
8328
|
+
const k = resolveOperand(items[0], r, this.ctx);
|
|
8329
|
+
const v = resolveOperand(items[1], r, this.ctx);
|
|
8330
|
+
if (k === null || k === undefined) continue;
|
|
8331
|
+
obj[String(k)] = v === undefined ? null : v;
|
|
8332
|
+
}
|
|
8333
|
+
}
|
|
8334
|
+
return obj;
|
|
8335
|
+
}
|
|
8308
8336
|
let values = noColumn
|
|
8309
8337
|
? rows.map(r => 1)
|
|
8310
8338
|
// Issue #114:VARIANCE(1,2,3) 这类多参数写法,所有参数值都纳入统计
|
|
@@ -8955,6 +8983,7 @@ class SQLExecutor {
|
|
|
8955
8983
|
node._rowCount = res.rows.length;
|
|
8956
8984
|
} else if (node.type === 'subquery') {
|
|
8957
8985
|
const res = await this.executeSelect(node.select);
|
|
8986
|
+
if (res.rows.length > 1) throw createError('ER_SUBSELECT_NO_1_ROW');
|
|
8958
8987
|
node._value = res.rows.length > 0 ? res.rows[0][0] : null;
|
|
8959
8988
|
} else if (node.type === 'in') {
|
|
8960
8989
|
const res = await this.executeSelect(node.subquery);
|
package/lib/tui.js
CHANGED
|
@@ -13,7 +13,8 @@ const os = require('os');
|
|
|
13
13
|
const Database = require('./database');
|
|
14
14
|
const { executeSQL } = require('./sql');
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// #300:历史文件不再内嵌 pid,跨会话可读
|
|
17
|
+
const HISTORY_FILE = path.join(os.homedir(), '.jsql-history');
|
|
17
18
|
const MAX_HISTORY = 500;
|
|
18
19
|
|
|
19
20
|
/* ---------- ANSI helpers ---------- */
|
|
@@ -39,6 +40,10 @@ function wswidth(str) {
|
|
|
39
40
|
let w = 0;
|
|
40
41
|
for (const ch of String(str)) {
|
|
41
42
|
const cp = ch.codePointAt(0);
|
|
43
|
+
// #298:emoji / 宽符号按 2 列,组合符/变体选择符按 0 列
|
|
44
|
+
if (cp >= 0x1f000 && cp <= 0x1faff) { w += 2; continue; }
|
|
45
|
+
if (cp >= 0x2600 && cp <= 0x27bf) { w += 2; continue; }
|
|
46
|
+
if ((cp >= 0x0300 && cp <= 0x036f) || (cp >= 0xfe00 && cp <= 0xfe0f) || cp === 0x200d) { continue; }
|
|
42
47
|
if (cp >= 0x1100 && (cp <= 0x115f || cp === 0x2329 || cp === 0x232a ||
|
|
43
48
|
(cp >= 0x2e80 && cp <= 0xa4cf && cp !== 0x303f) ||
|
|
44
49
|
(cp >= 0xac00 && cp <= 0xd7a3) || (cp >= 0xf900 && cp <= 0xfaff) ||
|
|
@@ -297,6 +302,8 @@ class TUIShell {
|
|
|
297
302
|
let inSQ = false, inDQ = false, parens = 0;
|
|
298
303
|
for (let i = 0; i < sql.length; i++) {
|
|
299
304
|
const c = sql[i];
|
|
305
|
+
// #299:反斜杠转义下一个字符(\' / \"),不能当成引号翻转
|
|
306
|
+
if (c === '\\' && (inSQ || inDQ)) { i++; continue; }
|
|
300
307
|
if (c === "'" && !inDQ) inSQ = !inSQ;
|
|
301
308
|
else if (c === '"' && !inSQ) inDQ = !inDQ;
|
|
302
309
|
else if (!inSQ && !inDQ) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsql-neo",
|
|
3
|
-
"version": "6.8.
|
|
3
|
+
"version": "6.8.23",
|
|
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/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.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 && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.test.js && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.test.js && node test/issue-279-306.test.js && node test/issue-271-283.test.js && node test/issue-265-307.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/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.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 && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.test.js && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.test.js && node test/issue-279-306.test.js && node test/issue-271-283.test.js && node test/issue-265-307.test.js && node test/issue-258-300.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/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.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 && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.test.js && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.test.js && node test/issue-279-306.test.js && node test/issue-271-283.test.js && node test/issue-265-307.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/issue-118-136.test.js && node test/issue-127.test.js && node test/issue-138-156.test.js && node test/issue-157-161.test.js && node test/issue-162-179.test.js && node test/issue-181-186.test.js && node test/issue-187.test.js && node test/issue-188-237.test.js && node test/issue-238-241.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 && node test/mongo-persistence.test.js && node test/mongo-objectid.test.js && node test/mongo-arrays.test.js && node test/issue-117.test.js && node test/issue-314-321.test.js && node test/issue-312-320.test.js && node test/issue-243-289.test.js && node test/issue-284-292.test.js && node test/issue-301-305.test.js && node test/issue-248-252.test.js && node test/issue-259-264.test.js && node test/issue-255-270.test.js && node test/issue-253-269.test.js && node test/issue-280-310.test.js && node test/issue-272-311.test.js && node test/issue-279-306.test.js && node test/issue-271-283.test.js && node test/issue-265-307.test.js && node test/issue-258-300.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,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Regression tests for #258 #293 #298 #299 #300.
|
|
3
|
+
* node test/issue-258-300.test.js
|
|
4
|
+
*/
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const ROOT = path.join(__dirname, '..');
|
|
9
|
+
const { Database, executeSQL } = require(path.join(ROOT, 'index.js'));
|
|
10
|
+
let passed = 0, failed = 0;
|
|
11
|
+
function ok(name, cond, extra) {
|
|
12
|
+
if (cond) { passed++; console.log('[OK]', name); }
|
|
13
|
+
else { failed++; console.log('[FAIL]', name, extra !== undefined ? '→ ' + JSON.stringify(extra) : ''); }
|
|
14
|
+
}
|
|
15
|
+
const q = (db, sql) => executeSQL(db, sql, { safety: false });
|
|
16
|
+
|
|
17
|
+
(async () => {
|
|
18
|
+
// #258
|
|
19
|
+
{
|
|
20
|
+
const db = new Database(':memory:');
|
|
21
|
+
await q(db, 'CREATE TABLE t (id INT)');
|
|
22
|
+
await q(db, 'INSERT INTO t VALUES (1),(2)');
|
|
23
|
+
let code = null;
|
|
24
|
+
try { await q(db, 'SELECT (SELECT id FROM t) AS x'); } catch (e) { code = e.code; }
|
|
25
|
+
ok('#258 scalar subquery with multiple rows -> 1242', code === 1242, code);
|
|
26
|
+
db.stop();
|
|
27
|
+
}
|
|
28
|
+
// #293
|
|
29
|
+
{
|
|
30
|
+
const db = new Database(':memory:');
|
|
31
|
+
await q(db, 'CREATE TABLE t (g TEXT, v INT)');
|
|
32
|
+
await q(db, "INSERT INTO t VALUES ('a',1),('a',2),('b',3)");
|
|
33
|
+
const arr = (await q(db, 'SELECT g, JSON_ARRAYAGG(v) AS j FROM t GROUP BY g ORDER BY g')).rows;
|
|
34
|
+
ok('#293 JSON_ARRAYAGG aggregates whole group', JSON.stringify(arr) === JSON.stringify([['a', [1, 2]], ['b', [3]]]), arr);
|
|
35
|
+
const obj = (await q(db, "SELECT JSON_OBJECTAGG(g, v) AS o FROM t")).rows;
|
|
36
|
+
ok('#293 JSON_OBJECTAGG builds object', obj.length === 1 && JSON.stringify(obj[0][0]) === JSON.stringify({ a: 2, b: 3 }), obj);
|
|
37
|
+
db.stop();
|
|
38
|
+
}
|
|
39
|
+
// #298 / #299
|
|
40
|
+
{
|
|
41
|
+
const tui = require(path.join(ROOT, 'lib', 'tui.js'));
|
|
42
|
+
ok('#298 emoji width counted as 2', tui.wswidth('😀') === 2 && tui.wswidth('abc😀') === 5, [tui.wswidth('😀'), tui.wswidth('abc😀')]);
|
|
43
|
+
const shell = Object.create(tui.TUIShell.prototype);
|
|
44
|
+
ok('#299 escaped quote keeps statement balanced', shell._statementComplete("SELECT 'a\\'b';") === true, shell._statementComplete("SELECT 'a\\'b';"));
|
|
45
|
+
}
|
|
46
|
+
// #300 history file has no pid
|
|
47
|
+
{
|
|
48
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-home-'));
|
|
49
|
+
const oldHome = process.env.HOME;
|
|
50
|
+
process.env.HOME = home;
|
|
51
|
+
const tuiPath = path.join(ROOT, 'lib', 'tui.js');
|
|
52
|
+
delete require.cache[require.resolve(tuiPath)];
|
|
53
|
+
const tui = require(tuiPath);
|
|
54
|
+
const shell = Object.create(tui.TUIShell.prototype);
|
|
55
|
+
shell.history = ['SELECT 1;'];
|
|
56
|
+
shell._saveHistory();
|
|
57
|
+
const files = fs.readdirSync(home);
|
|
58
|
+
ok('#300 history file is session-independent', files.includes('.jsql-history'), files);
|
|
59
|
+
process.env.HOME = oldHome;
|
|
60
|
+
delete require.cache[require.resolve(tuiPath)];
|
|
61
|
+
}
|
|
62
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
63
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
64
|
+
})().catch((e) => { console.error('FATAL', e); process.exit(1); });
|