jsql-neo 6.10.1 → 6.10.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 +1 -1
- package/index.js +1 -1
- package/lib/jsql_format.js +22 -9
- package/lib/migrate.js +2 -0
- package/lib/mod.js +9 -3
- package/lib/mongo_server.js +5 -0
- package/lib/tui.js +4 -1
- package/package.json +4 -4
- package/test/issue-384.test.js +41 -0
- package/test/issue-480.test.js +42 -0
- package/test/issue-485.test.js +47 -0
- package/test/issue-501-506.test.js +29 -0
- package/test/issue-502.test.js +18 -0
- package/test/issue-545.test.js +38 -0
- package/test/mongo-update-dates.test.js +128 -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.10.
|
|
6
|
+
> **v6.10.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
|

|
|
9
9
|

|
package/index.js
CHANGED
package/lib/jsql_format.js
CHANGED
|
@@ -161,19 +161,24 @@ function encRowInPlace(row, encoders, scratch, offStart) {
|
|
|
161
161
|
// Build reusable field encoders from schema
|
|
162
162
|
// 无 schema 的表(如 Mongo collection 以 {} 建表):字段从行数据本身取并集。
|
|
163
163
|
// 否则 0 个编码器会把每一行刷成 4 字节空桩,重载时一行都读不回来。
|
|
164
|
+
// 有 schema 时以 schema 字段为底、再并入行里出现的未知字段:Mongo 集合的
|
|
165
|
+
// schema 是首份文档推断出来的(_inferSchema),后续更新新增的字段不在其中,
|
|
166
|
+
// 若按 schema 硬裁会把新字段静默丢弃(内存可见、重载即消失)。
|
|
164
167
|
// shortcut: 某行缺的字段重载后变 null(不区分「缺字段」和「值为 null」),需要严格区分时再升级
|
|
165
168
|
function buildEncoders(schema, rows) {
|
|
166
169
|
const skip = f => f !== '_softDelete'; // _softDelete 是 schema 配置键,不会是数据字段
|
|
167
|
-
const schemaFields = Object.keys(schema || {}).filter(skip);
|
|
168
|
-
if (schemaFields.length > 0) {
|
|
169
|
-
return schemaFields.map(name => ({ name, nameEnc: enc(name) }));
|
|
170
|
-
}
|
|
171
170
|
const seen = new Set();
|
|
171
|
+
const fields = [];
|
|
172
|
+
for (const name of Object.keys(schema || {})) {
|
|
173
|
+
if (skip(name) && !seen.has(name)) { seen.add(name); fields.push(name); }
|
|
174
|
+
}
|
|
172
175
|
for (const row of rows || []) {
|
|
173
176
|
if (!row) continue;
|
|
174
|
-
for (const f of Object.keys(row))
|
|
177
|
+
for (const f of Object.keys(row)) {
|
|
178
|
+
if (skip(f) && !seen.has(f)) { seen.add(f); fields.push(f); }
|
|
179
|
+
}
|
|
175
180
|
}
|
|
176
|
-
return
|
|
181
|
+
return fields.map(name => ({ name, nameEnc: enc(name) }));
|
|
177
182
|
}
|
|
178
183
|
|
|
179
184
|
const encRow = encRowInPlace;
|
|
@@ -431,10 +436,17 @@ class JSQLFormat {
|
|
|
431
436
|
|
|
432
437
|
for (const [name, info] of Object.entries(allTables)) {
|
|
433
438
|
const { schema, rows, pkField } = info;
|
|
434
|
-
|
|
435
|
-
|
|
439
|
+
// #545:空表也要登记到 superblock,否则重开后 DDL 静默消失。
|
|
440
|
+
// 之前 rows.length===0 直接 continue,表名/schema 既不进 superblock 也不写索引块。
|
|
436
441
|
const tableId = this._nextTableId++;
|
|
437
442
|
this.tables.set(name, { schema, rowCount:0, pkBlock:0, dataBlock:0, tableId });
|
|
443
|
+
if (!rows || rows.length === 0) {
|
|
444
|
+
// #545:空表也要写一个空数据块,让 _load 能从 superblock 重建出这张表。
|
|
445
|
+
// 走下面的统一 phase2 编码路径(含 gzip/加密/finalize 校验),
|
|
446
|
+
// 不能直接写裸块,否则校验和不通过。
|
|
447
|
+
pending.push({ name, tableId, rawBlocks: [Buffer.alloc(0)], blockIds: [this._alloc()], pkEntries: [] });
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
438
450
|
|
|
439
451
|
const pkEntries = [];
|
|
440
452
|
const rawBlocks = [];
|
|
@@ -576,7 +588,8 @@ class JSQLFormat {
|
|
|
576
588
|
|
|
577
589
|
const entries = this.pkIdx.get(name) || [];
|
|
578
590
|
this.pkIdx.set(name, entries);
|
|
579
|
-
|
|
591
|
+
// upserts 也要传给 buildEncoders:schema 之外的行字段不能被静默裁掉
|
|
592
|
+
const encoders = buildEncoders(t.schema, upserts);
|
|
580
593
|
const scratch = Buffer.allocUnsafe(SZ.DATA);
|
|
581
594
|
const written = [];
|
|
582
595
|
|
package/lib/migrate.js
CHANGED
|
@@ -506,6 +506,8 @@ async function exportToFile(engine, table, filePath, opts = {}) {
|
|
|
506
506
|
const schema = await engine.getTableSchema(table);
|
|
507
507
|
if (!schema) throw new Error(`Table '${table}' does not exist`);
|
|
508
508
|
const columns = Object.keys(schema);
|
|
509
|
+
// #480:与 Database#exportCSV 对齐,递归创建缺失的父目录
|
|
510
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
509
511
|
const stream = fs.createWriteStream(filePath, { encoding: 'utf8' });
|
|
510
512
|
// 防止磁盘写满等异步错误在 write 回调之外变成未捕获异常
|
|
511
513
|
stream.on('error', () => {});
|
package/lib/mod.js
CHANGED
|
@@ -232,9 +232,15 @@ class ModuleManager {
|
|
|
232
232
|
applyTo(db) {
|
|
233
233
|
const enabled = this._sortEnabled();
|
|
234
234
|
for (const entry of enabled) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
// #384: 逐模块失败隔离,与 enableAll() 口径对齐——单个模块
|
|
236
|
+
// 加载/安装抛错只跳过该模块,不阻断排在后面的其它已启用模块。
|
|
237
|
+
try {
|
|
238
|
+
const plugin = this._loadStoredModule(entry);
|
|
239
|
+
if (!plugin) continue;
|
|
240
|
+
db.use(plugin);
|
|
241
|
+
} catch (e) {
|
|
242
|
+
if (process.env.JSQL_DEBUG) console.warn(`[mod] Skipping module '${entry.name}' in applyTo: ${e.message}`);
|
|
243
|
+
}
|
|
238
244
|
}
|
|
239
245
|
return db;
|
|
240
246
|
}
|
package/lib/mongo_server.js
CHANGED
|
@@ -385,6 +385,11 @@ function bsonReadValue(buf, pos, type, end) {
|
|
|
385
385
|
|
|
386
386
|
function cloneDoc(v) {
|
|
387
387
|
if (v instanceof ObjectId) return v;
|
|
388
|
+
// Date / Buffer 必须特判:Date 的自有枚举键为空,走通用对象分支会克隆成
|
|
389
|
+
// {}(每次 $set 更新都把行里既有的 Date 静默摧毁);Buffer 会被克隆成
|
|
390
|
+
// {0:1,1:2,…} 普通对象,丢掉 Buffer 类型
|
|
391
|
+
if (v instanceof Date) return new Date(v.getTime());
|
|
392
|
+
if (Buffer.isBuffer(v)) return Buffer.from(v);
|
|
388
393
|
if (Array.isArray(v)) return v.map(cloneDoc);
|
|
389
394
|
if (v && typeof v === 'object') {
|
|
390
395
|
const out = {};
|
package/lib/tui.js
CHANGED
|
@@ -171,7 +171,10 @@ class TUIShell {
|
|
|
171
171
|
_saveHistory() {
|
|
172
172
|
try {
|
|
173
173
|
const head = this.history.slice(-MAX_HISTORY);
|
|
174
|
-
|
|
174
|
+
// #485:历史可能含口令/敏感字面量,按私有凭据处理,落盘即 0600
|
|
175
|
+
fs.writeFileSync(HISTORY_FILE, head.join('\n') + '\n', { mode: 0o600 });
|
|
176
|
+
// 已存在的文件权限过宽时收敛(对齐 lib/mod.js 对 mod.config 的做法)
|
|
177
|
+
try { fs.chmodSync(HISTORY_FILE, 0o600); } catch (_) { /* ignore */ }
|
|
175
178
|
} catch (e) { /* ignore */ }
|
|
176
179
|
}
|
|
177
180
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsql-neo",
|
|
3
|
-
"version": "6.10.
|
|
3
|
+
"version": "6.10.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,18 +52,18 @@
|
|
|
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 && node test/issue-258-300.test.js && node test/issue-247-295-277.test.js && node test/issue-322-325.test.js && node test/issue-357-365.test.js && node test/issue-372-387.test.js && node test/issue-383-402.test.js && node test/issue-369-394.test.js && node test/issue-352-386.test.js && node test/issue-395-430.test.js && node test/btree.test.js && node test/regress-5.1.0.js && node test/native-multi-instance.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/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.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/coverage.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/savepoint.test.js && node test/alter-table.test.js && node test/identifier-keywords.test.js && node test/null-semantics.test.js && node test/sql-semantics.test.js && node test/filter-compile.test.js && node test/compat-v1.test.js && node test/issue-327-418.test.js && node test/issue-341-419.test.js && node test/issue-450-454.test.js && node test/issue-445-449.test.js && node test/issue-460-464.test.js && node test/issue-455-459.test.js && node test/issue-465-469.test.js && node test/issue-471.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/mongo-update-dates.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 && node test/issue-247-295-277.test.js && node test/issue-322-325.test.js && node test/issue-357-365.test.js && node test/issue-372-387.test.js && node test/issue-383-402.test.js && node test/issue-369-394.test.js && node test/issue-352-386.test.js && node test/issue-395-430.test.js && node test/btree.test.js && node test/regress-5.1.0.js && node test/native-multi-instance.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/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.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/coverage.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/savepoint.test.js && node test/alter-table.test.js && node test/identifier-keywords.test.js && node test/null-semantics.test.js && node test/sql-semantics.test.js && node test/filter-compile.test.js && node test/compat-v1.test.js && node test/issue-327-418.test.js && node test/issue-341-419.test.js && node test/issue-450-454.test.js && node test/issue-445-449.test.js && node test/issue-460-464.test.js && node test/issue-455-459.test.js && node test/issue-465-469.test.js && node test/issue-471.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 && node test/issue-258-300.test.js && node test/issue-247-295-277.test.js && node test/issue-322-325.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/mongo-update-dates.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 && node test/issue-247-295-277.test.js && node test/issue-322-325.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",
|
|
64
64
|
"test:cte": "node test/recursive-cte.test.js",
|
|
65
65
|
"test:index": "node test/index-ddl.test.js",
|
|
66
|
-
"test:mongo": "node test/mongo-group.test.js && node test/mongo-arrays.test.js",
|
|
66
|
+
"test:mongo": "node test/mongo-group.test.js && node test/mongo-arrays.test.js && node test/mongo-update-dates.test.js",
|
|
67
67
|
"test:multi": "node test/multiprotocol.test.js",
|
|
68
68
|
"test:star": "node test/star-nag.test.js",
|
|
69
69
|
"test:savepoint": "node test/savepoint.test.js",
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { Database } = require('../index.js');
|
|
6
|
+
const { ModuleManager } = require('../lib/mod.js');
|
|
7
|
+
|
|
8
|
+
const TMP = path.join(__dirname, '.tmp-mod384');
|
|
9
|
+
|
|
10
|
+
function writeMod(name, installBody) {
|
|
11
|
+
const file = path.join(TMP, name + '.js');
|
|
12
|
+
fs.writeFileSync(file, `module.exports = { name: '${name}', install() { ${installBody} } };\n`, 'utf8');
|
|
13
|
+
return { name, enabled: true, path: file };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
(async () => {
|
|
17
|
+
fs.mkdirSync(TMP, { recursive: true });
|
|
18
|
+
const a = writeMod('a', '');
|
|
19
|
+
const b = writeMod('b', "throw new Error('boom-b');");
|
|
20
|
+
const c = writeMod('c', '');
|
|
21
|
+
|
|
22
|
+
const cfg = path.join(TMP, 'config.json');
|
|
23
|
+
try { fs.unlinkSync(cfg); } catch (e) {}
|
|
24
|
+
const mgr = new ModuleManager(cfg);
|
|
25
|
+
mgr._modules = [a, b, c];
|
|
26
|
+
|
|
27
|
+
const db = new Database(':memory:');
|
|
28
|
+
mgr.applyTo(db);
|
|
29
|
+
const names = db._plugins.map(p => p.name);
|
|
30
|
+
assert(names.includes('a'), '模块 a 应被应用');
|
|
31
|
+
assert(names.includes('c'), '模块 c 应被应用(b 抛错不应中断后续)');
|
|
32
|
+
assert(!names.includes('b'), '模块 b 安装失败不应出现在插件列表');
|
|
33
|
+
await db.stop();
|
|
34
|
+
|
|
35
|
+
fs.rmSync(TMP, { recursive: true, force: true });
|
|
36
|
+
console.log('issue-384: PASS');
|
|
37
|
+
})().catch(e => {
|
|
38
|
+
try { fs.rmSync(TMP, { recursive: true, force: true }); } catch (_) {}
|
|
39
|
+
console.error('issue-384: FAIL', e.message);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
// #480: exportToFile 自动创建缺失父目录
|
|
8
|
+
let passed = 0, failed = 0;
|
|
9
|
+
function ok(name, fn) {
|
|
10
|
+
return Promise.resolve().then(fn).then(() => { passed++; console.log('ok -', name); })
|
|
11
|
+
.catch(e => { failed++; console.log('not ok -', name, '\n ', e.message); });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
(async () => {
|
|
15
|
+
const { Database } = require('../index.js');
|
|
16
|
+
const migrate = require('../lib/migrate');
|
|
17
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-h480-'));
|
|
18
|
+
const db = new Database(':memory:', { safety: false });
|
|
19
|
+
try {
|
|
20
|
+
await db.createTable('x', { id: 'integer' });
|
|
21
|
+
await db.insert('x', [{ id: 1 }]);
|
|
22
|
+
const out = path.join(dir, 'no-such-dir', 'nested', 'x.csv');
|
|
23
|
+
|
|
24
|
+
await ok('#480 exportToFile 递归建父目录', async () => {
|
|
25
|
+
await migrate.exportToFile(db, 'x', out);
|
|
26
|
+
assert.ok(fs.existsSync(out), 'export file should exist');
|
|
27
|
+
const content = fs.readFileSync(out, 'utf8');
|
|
28
|
+
assert.ok(content.length > 0, 'export file should not be empty');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
await ok('#480 exportToFile JSON 同样建目录', async () => {
|
|
32
|
+
const out2 = path.join(dir, 'another-dir', 'x.json');
|
|
33
|
+
await migrate.exportToFile(db, 'x', out2);
|
|
34
|
+
assert.ok(fs.existsSync(out2), 'json export file should exist');
|
|
35
|
+
});
|
|
36
|
+
} finally {
|
|
37
|
+
await db.stop();
|
|
38
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
39
|
+
}
|
|
40
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
41
|
+
if (failed) process.exitCode = 1;
|
|
42
|
+
})();
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
// #485: TUI 历史文件落盘应为 0600
|
|
8
|
+
let passed = 0, failed = 0;
|
|
9
|
+
function ok(name, fn) {
|
|
10
|
+
return Promise.resolve().then(fn).then(() => { passed++; console.log('ok -', name); })
|
|
11
|
+
.catch(e => { failed++; console.log('not ok -', name, '\n ', e.message); });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
(async () => {
|
|
15
|
+
const fakeHome = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-h485-'));
|
|
16
|
+
const prevHome = process.env.HOME;
|
|
17
|
+
process.env.HOME = fakeHome;
|
|
18
|
+
try {
|
|
19
|
+
// 清除模块缓存,让 HISTORY_FILE 使用 fake HOME
|
|
20
|
+
const tuiPath = require.resolve('../lib/tui');
|
|
21
|
+
delete require.cache[tuiPath];
|
|
22
|
+
const { createTUI } = require('../lib/tui');
|
|
23
|
+
const tui = createTUI({ dataDir: null, db: 'default' });
|
|
24
|
+
tui._pushHistory("SELECT * FROM users WHERE password = 'secret'");
|
|
25
|
+
|
|
26
|
+
await ok('#485 历史文件权限为 0600', () => {
|
|
27
|
+
const f = path.join(fakeHome, '.jsql-history');
|
|
28
|
+
assert.ok(fs.existsSync(f), 'history file should exist');
|
|
29
|
+
const mode = fs.statSync(f).mode & 0o777;
|
|
30
|
+
assert.strictEqual(mode, 0o600, `expected 0600, got ${mode.toString(8)}`);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// 已存在且权限过宽的文件也应被收敛
|
|
34
|
+
await ok('#485 已存在的宽权限文件被收敛', () => {
|
|
35
|
+
const f = path.join(fakeHome, '.jsql-history');
|
|
36
|
+
fs.chmodSync(f, 0o644);
|
|
37
|
+
tui._pushHistory('SELECT 2');
|
|
38
|
+
const mode = fs.statSync(f).mode & 0o777;
|
|
39
|
+
assert.strictEqual(mode, 0o600, `expected 0600, got ${mode.toString(8)}`);
|
|
40
|
+
});
|
|
41
|
+
} finally {
|
|
42
|
+
process.env.HOME = prevHome;
|
|
43
|
+
fs.rmSync(fakeHome, { recursive: true, force: true });
|
|
44
|
+
}
|
|
45
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
46
|
+
if (failed) process.exitCode = 1;
|
|
47
|
+
})();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
// #501 / #506: PLUGINS.md 文档修正
|
|
7
|
+
let passed = 0, failed = 0;
|
|
8
|
+
function ok(name, fn) {
|
|
9
|
+
try { fn(); passed++; console.log('ok -', name); }
|
|
10
|
+
catch (e) { failed++; console.log('not ok -', name, '\n ', e.message); }
|
|
11
|
+
}
|
|
12
|
+
const md = fs.readFileSync(path.join(__dirname, '..', 'PLUGINS.md'), 'utf8');
|
|
13
|
+
|
|
14
|
+
ok('#506 beforeFlush/afterFlush 支持 Pure JS Database (N/W/D)', () => {
|
|
15
|
+
const bf = md.split('\n').find(l => l.includes('`beforeFlush`'));
|
|
16
|
+
const af = md.split('\n').find(l => l.includes('`afterFlush`'));
|
|
17
|
+
assert.ok(bf && bf.includes('N/W/D'), `beforeFlush row: ${bf}`);
|
|
18
|
+
assert.ok(af && af.includes('N/W/D'), `afterFlush row: ${af}`);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
ok('#501 文档不再声称模块默认可 require', () => {
|
|
22
|
+
assert.ok(!md.includes('模块文件可 `require` 本地依赖,但**不会被隔离**'),
|
|
23
|
+
'旧的错误表述应被移除');
|
|
24
|
+
assert.ok(md.includes('不提供 `require`'), '应说明默认沙箱不提供 require');
|
|
25
|
+
assert.ok(md.includes('JSQL_ALLOW_UNSAFE_MODULES=1'), '应说明需设环境变量才放开');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
29
|
+
if (failed) process.exitCode = 1;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
// #502: PLUGINS.md 统一引擎 API 示例里的 findById/updateById/removeById
|
|
7
|
+
// 都是 async,示例必须 await,否则拿到 Promise、字段全 undefined。
|
|
8
|
+
const doc = fs.readFileSync(path.join(__dirname, '..', 'PLUGINS.md'), 'utf8');
|
|
9
|
+
const block = doc.match(/```js[\s\S]*?await db\.start\(\)[\s\S]*?```/);
|
|
10
|
+
assert(block, '应能找到统一引擎 API 代码块');
|
|
11
|
+
const code = block[0];
|
|
12
|
+
|
|
13
|
+
assert(/await db\.findById\(/.test(code), 'findById 示例必须 await');
|
|
14
|
+
assert(/await db\.updateById\(/.test(code), 'updateById 示例必须 await');
|
|
15
|
+
assert(/await db\.removeById\(/.test(code), 'removeById 示例必须 await');
|
|
16
|
+
assert(!/或 await(WASM)/.test(code), '不应保留误导性的「或 await(WASM)」注释');
|
|
17
|
+
|
|
18
|
+
console.log('issue-502: PASS');
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('assert');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
// #545: .jsql 单文件模式零行表重开后不消失
|
|
8
|
+
let passed = 0, failed = 0;
|
|
9
|
+
function ok(name, fn) {
|
|
10
|
+
return Promise.resolve().then(fn).then(() => { passed++; console.log('ok -', name); })
|
|
11
|
+
.catch(e => { failed++; console.log('not ok -', name, '\n ', e.message); });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
(async () => {
|
|
15
|
+
const { Database } = require('../index.js');
|
|
16
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-h545-'));
|
|
17
|
+
const file = path.join(dir, 'db.jsql');
|
|
18
|
+
try {
|
|
19
|
+
let db = new Database(file, { wal: false, fileLock: false, safety: false });
|
|
20
|
+
await db.query('CREATE TABLE t1(id INTEGER PRIMARY KEY, v STRING)');
|
|
21
|
+
await db.query('CREATE TABLE t2(id INTEGER PRIMARY KEY, v STRING)');
|
|
22
|
+
await db.insertMany('t1', [{ id: 1, v: 'a' }]);
|
|
23
|
+
db.save();
|
|
24
|
+
db.close();
|
|
25
|
+
|
|
26
|
+
await ok('#545 空表 t2 重开后仍存在', () => {
|
|
27
|
+
db = new Database(file, { wal: false, fileLock: false, safety: false });
|
|
28
|
+
const tables = db.getTables();
|
|
29
|
+
assert.ok(tables.includes('t2'), `expected t2 in ${JSON.stringify(tables)}`);
|
|
30
|
+
assert.ok(tables.includes('t1'), `expected t1 in ${JSON.stringify(tables)}`);
|
|
31
|
+
db.close();
|
|
32
|
+
});
|
|
33
|
+
} finally {
|
|
34
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
35
|
+
}
|
|
36
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
37
|
+
if (failed) process.exitCode = 1;
|
|
38
|
+
})();
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* updateOne / findAndModify / updateById 路径上的 Date 摧毁(外部报告):
|
|
3
|
+
*
|
|
4
|
+
* 1. cloneDoc(mongo_server.js)按自有枚举键深拷贝 —— Date 键为空,每次
|
|
5
|
+
* $set 更新把行里既有的 Date(顶层 / 嵌套 / 数组内)静默克隆成 {};
|
|
6
|
+
* ObjectId 有特判、Date/Buffer 没有。Buffer 会被克隆成 {0:1,1:2,…}。
|
|
7
|
+
* 2. buildEncoders(jsql_format.js)在有 schema 时只编码 schema 字段 ——
|
|
8
|
+
* Mongo 集合的 schema 由首份文档推断(_inferSchema),后续更新新增的
|
|
9
|
+
* 字段不在 schema 里,写盘时被静默丢弃:内存可见、重载即消失。
|
|
10
|
+
*
|
|
11
|
+
* 覆盖:报告原始复现形状、同次 $set 新增的 Date、replacement 更新、
|
|
12
|
+
* findAndModify、$push Date、hybrid 磁盘重载、更新后新增字段、Buffer。
|
|
13
|
+
*/
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const { Database, createMongoServer } = require(path.join(__dirname, '..', 'index.js'));
|
|
18
|
+
const { ObjectId } = require(path.join(__dirname, '..', 'lib', 'objectid.js'));
|
|
19
|
+
|
|
20
|
+
let pass = 0, fail = 0;
|
|
21
|
+
function ok(name, cond, extra) {
|
|
22
|
+
if (cond) { pass++; console.log('[OK] ', name); }
|
|
23
|
+
else { fail++; console.log('[FAIL]', name, extra !== undefined ? '-> ' + JSON.stringify(extra).slice(0, 200) : ''); }
|
|
24
|
+
}
|
|
25
|
+
const isDate = (v) => v instanceof Date;
|
|
26
|
+
const ts = (v) => (v instanceof Date ? v.getTime() : String(v));
|
|
27
|
+
|
|
28
|
+
async function insert(srv, docs) {
|
|
29
|
+
const r = await srv._dispatch('insert', { insert: 'c', $db: 'test', documents: docs });
|
|
30
|
+
if (r.ok !== 1 || r.n !== docs.length) throw new Error('insert failed: ' + JSON.stringify(r));
|
|
31
|
+
}
|
|
32
|
+
async function find(srv, filter = {}) {
|
|
33
|
+
const r = await srv._dispatch('find', { find: 'c', $db: 'test', filter });
|
|
34
|
+
return r.cursor ? r.cursor.firstBatch : [];
|
|
35
|
+
}
|
|
36
|
+
async function updateOne(srv, q, u) {
|
|
37
|
+
const r = await srv._dispatch('update', { update: 'c', $db: 'test', updates: [{ q, u }] });
|
|
38
|
+
if (r.ok !== 1 || r.n !== 1) throw new Error('update failed: ' + JSON.stringify(r));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
(async () => {
|
|
42
|
+
try {
|
|
43
|
+
/* ---------- 1. 报告原始复现:$set 更新不摧毁既有 Date ---------- */
|
|
44
|
+
{
|
|
45
|
+
const srv = createMongoServer({ port: 0, noAuth: true, dataDir: ':memory:' });
|
|
46
|
+
const D = '2024-05-05T12:29:49.835Z';
|
|
47
|
+
await insert(srv, [{
|
|
48
|
+
_id: new ObjectId('aaaaaaaaaaaaaaaaaaaaaaaa'),
|
|
49
|
+
status: 'active',
|
|
50
|
+
createdAt: new Date(D),
|
|
51
|
+
lp: { optimizedStartDate: new Date(D) },
|
|
52
|
+
records: [{ n: 1, when: new Date(D) }],
|
|
53
|
+
bin: Buffer.from([1, 2, 3]),
|
|
54
|
+
}]);
|
|
55
|
+
await updateOne(srv, { status: 'active' }, { $set: { status: 'done', fresh: new Date('2026-04-01T00:00:00Z') } });
|
|
56
|
+
const doc = (await find(srv))[0];
|
|
57
|
+
|
|
58
|
+
ok('$set 后顶层 Date 保持', isDate(doc.createdAt) && ts(doc.createdAt) === new Date(D).getTime(), doc.createdAt);
|
|
59
|
+
ok('$set 后嵌套 Date 保持', isDate(doc.lp.optimizedStartDate) && ts(doc.lp.optimizedStartDate) === new Date(D).getTime(), doc.lp);
|
|
60
|
+
ok('$set 后数组内对象 Date 保持', isDate(doc.records[0].when) && ts(doc.records[0].when) === new Date(D).getTime(), doc.records);
|
|
61
|
+
ok('$set 后 Buffer 保持', Buffer.isBuffer(doc.bin) && doc.bin.equals(Buffer.from([1, 2, 3])), doc.bin);
|
|
62
|
+
ok('同次 $set 新增的 Date 存活', isDate(doc.fresh), doc.fresh);
|
|
63
|
+
ok('同次 $set 普通字段生效', doc.status === 'done', doc.status);
|
|
64
|
+
|
|
65
|
+
// $push 一个 Date 进数组
|
|
66
|
+
await updateOne(srv, { _id: new ObjectId('aaaaaaaaaaaaaaaaaaaaaaaa') }, { $push: { records: { n: 2, when: new Date('2026-05-01T00:00:00Z') } } });
|
|
67
|
+
const doc2 = (await find(srv))[0];
|
|
68
|
+
ok('$push 的 Date 存活', doc2.records.length === 2 && isDate(doc2.records[1].when), doc2.records);
|
|
69
|
+
ok('$push 不破坏既有元素', isDate(doc2.records[0].when), doc2.records);
|
|
70
|
+
|
|
71
|
+
// replacement 更新(整体替换文档)里的 Date
|
|
72
|
+
await srv._dispatch('update', { update: 'c', $db: 'test', updates: [
|
|
73
|
+
{ q: { status: 'done' }, u: { _id: new ObjectId('aaaaaaaaaaaaaaaaaaaaaaaa'), status: 'replaced', at: new Date('2026-06-01T00:00:00Z') } },
|
|
74
|
+
]});
|
|
75
|
+
const doc3 = (await find(srv))[0];
|
|
76
|
+
ok('replacement 更新中的 Date 保持', isDate(doc3.at) && doc3.status === 'replaced', doc3);
|
|
77
|
+
|
|
78
|
+
// findAndModify $set
|
|
79
|
+
const fam = await srv._dispatch('findAndModify', {
|
|
80
|
+
findAndModify: 'c', $db: 'test', query: {}, update: { $set: { touched: new Date('2026-07-01T00:00:00Z') } }, new: true,
|
|
81
|
+
});
|
|
82
|
+
ok('findAndModify $set 的 Date 存活且旧字段不损', isDate(fam.value.at) && isDate(fam.value.touched), { at: fam.value.at, touched: fam.value.touched });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* ---------- 2. 磁盘重载:Date + 更新新增字段都不得丢 ---------- */
|
|
86
|
+
{
|
|
87
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-upd-date-'));
|
|
88
|
+
const srv = createMongoServer({ port: 0, noAuth: true, dataDir: dir });
|
|
89
|
+
await insert(srv, [{ _id: 1, createdAt: new Date('2026-01-01T00:00:00Z'), nested: { at: new Date('2026-02-01T00:00:00Z') } }]);
|
|
90
|
+
await updateOne(srv, { _id: 1 }, { $set: { status: 'done', fresh: new Date('2026-04-01T00:00:00Z'), extra: 42 } });
|
|
91
|
+
await new Promise((r) => srv.close(r));
|
|
92
|
+
|
|
93
|
+
const srv2 = createMongoServer({ port: 0, noAuth: true, dataDir: dir });
|
|
94
|
+
const doc = (await find(srv2))[0];
|
|
95
|
+
ok('重载后既有顶层 Date 保持', isDate(doc.createdAt) && ts(doc.createdAt) === new Date('2026-01-01T00:00:00Z').getTime(), doc.createdAt);
|
|
96
|
+
ok('重载后嵌套 Date 保持', isDate(doc.nested && doc.nested.at), doc.nested);
|
|
97
|
+
ok('重载后同次 $set 的 Date 保持(buildEncoders 裁字段)', isDate(doc.fresh), doc.fresh);
|
|
98
|
+
ok('重载后更新新增的非 Date 字段保持(schema 推断锁死)', doc.extra === 42, doc.extra);
|
|
99
|
+
ok('重载后普通 $set 字段保持', doc.status === 'done', doc.status);
|
|
100
|
+
await new Promise((r) => srv2.close(r));
|
|
101
|
+
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* ---------- 3. 文档 API updateById(schemaless + 磁盘重载) ---------- */
|
|
105
|
+
{
|
|
106
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-upd-date2-'));
|
|
107
|
+
const db = new Database(path.join(dir, 'test'), { mode: 'hybrid' });
|
|
108
|
+
await db.createTable('d', {});
|
|
109
|
+
await db.insert('d', { _id: 1, when: new Date('2026-01-01T00:00:00Z') });
|
|
110
|
+
await db.updateById('d', 1, { status: 'done', fresh: new Date('2026-04-01T00:00:00Z') });
|
|
111
|
+
await db.stop();
|
|
112
|
+
|
|
113
|
+
const db2 = new Database(path.join(dir, 'test'), { mode: 'hybrid' });
|
|
114
|
+
const rows = await db2.find('d', {});
|
|
115
|
+
const r = rows[0];
|
|
116
|
+
ok('updateById 重载后既有 Date 保持', isDate(r.when), r.when);
|
|
117
|
+
ok('updateById 重载后新增 Date / 字段保持', isDate(r.fresh) && r.status === 'done', r);
|
|
118
|
+
await db2.stop();
|
|
119
|
+
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
|
|
120
|
+
}
|
|
121
|
+
} catch (e) {
|
|
122
|
+
fail++;
|
|
123
|
+
console.log('[FAIL] unexpected exception:', e && e.stack || e);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log(`\n${fail === 0 ? 'ALL PASS' : 'FAILURES'} — ${pass} passed, ${fail} failed\n`);
|
|
127
|
+
if (fail > 0) process.exit(1);
|
|
128
|
+
})();
|