jsql-neo 6.8.19 → 6.8.21
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/mongo_server.js +35 -4
- package/lib/mysql_server.js +16 -3
- package/lib/nedb_compat.js +15 -3
- package/lib/pg_server.js +11 -1
- package/lib/sqlite_compat.js +2 -0
- package/lib/sqlite_worker.js +13 -1
- package/package.json +3 -3
- package/test/issue-271-283.test.js +86 -0
- package/test/issue-279-306.test.js +76 -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.21** — 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/mongo_server.js
CHANGED
|
@@ -314,6 +314,8 @@ class MongoServer {
|
|
|
314
314
|
this._dbCollections = new Map(); // db name → Set of collection names
|
|
315
315
|
this._engineByDb = new Map(); // db name → Database (standalone 模式)
|
|
316
316
|
this._indexesByColl = new Map(); // "db.coll" → [{ name, columns, unique }]
|
|
317
|
+
this._cursors = new Map(); // #278:find/getMore 游标
|
|
318
|
+
this._nextCursorId = 1;
|
|
317
319
|
this._autoCollections = new Set(); // db.collection 由 Mongo 自动建表(可继续补列)
|
|
318
320
|
}
|
|
319
321
|
|
|
@@ -812,10 +814,28 @@ class MongoServer {
|
|
|
812
814
|
if (effLimit > 0) rows = rows.slice(0, effLimit);
|
|
813
815
|
const projection = doc.projection || doc.fields;
|
|
814
816
|
if (projection) rows = rows.map(r => applyProjection(r, projection));
|
|
815
|
-
|
|
817
|
+
// #278:尊重 batchSize,剩余行留在游标里由 getMore 取
|
|
818
|
+
const batchSize = Number(doc.batchSize) > 0 ? Math.trunc(Number(doc.batchSize)) : 101;
|
|
819
|
+
const ns = `${this._dbOf(doc)}.${coll}`;
|
|
820
|
+
const firstBatch = rows.slice(0, batchSize);
|
|
821
|
+
let cursorId = 0;
|
|
822
|
+
if (rows.length > firstBatch.length) {
|
|
823
|
+
cursorId = this._nextCursorId++;
|
|
824
|
+
this._cursors.set(cursorId, { rows: rows.slice(firstBatch.length), ns, coll, db: this._dbOf(doc), batchSize });
|
|
825
|
+
}
|
|
826
|
+
return { ok: 1, cursor: { id: { $long: cursorId }, ns, firstBatch } };
|
|
827
|
+
}
|
|
828
|
+
case 'getMore': {
|
|
829
|
+
const idIn = doc.getMore;
|
|
830
|
+
const id = idIn && typeof idIn === 'object' ? Number(idIn.$long ?? idIn.low ?? 0) : Number(idIn || 0);
|
|
831
|
+
const cur = this._cursors.get(id);
|
|
832
|
+
if (!cur) return { ok: 0, errmsg: 'cursor not found', code: 43 };
|
|
833
|
+
const nextBatch = cur.rows.slice(0, cur.batchSize);
|
|
834
|
+
cur.rows = cur.rows.slice(nextBatch.length);
|
|
835
|
+
let nextId = id;
|
|
836
|
+
if (cur.rows.length === 0) { this._cursors.delete(id); nextId = 0; }
|
|
837
|
+
return { ok: 1, cursor: { id: { $long: nextId }, ns: cur.ns, nextBatch } };
|
|
816
838
|
}
|
|
817
|
-
case 'getMore':
|
|
818
|
-
return { ok: 1, cursor: { id: { $long: 0 }, ns: String(doc.collection || ''), nextBatch: [] } };
|
|
819
839
|
case 'update': {
|
|
820
840
|
const coll = String(doc.update);
|
|
821
841
|
const engine = await this._ensureCollection(coll, this._dbOf(doc));
|
|
@@ -942,7 +962,12 @@ class MongoServer {
|
|
|
942
962
|
const engine = await this._ensureCollection(coll, this._dbOf(doc));
|
|
943
963
|
const pipeline = doc.pipeline || [];
|
|
944
964
|
let rows = await engine.find(coll, {});
|
|
965
|
+
const STAGES = new Set(['$match', '$count', '$limit', '$skip', '$sort', '$project', '$unwind', '$lookup', '$group']);
|
|
945
966
|
for (const stage of pipeline) {
|
|
967
|
+
const stageName = Object.keys(stage || {})[0];
|
|
968
|
+
if (!STAGES.has(stageName)) {
|
|
969
|
+
return { ok: 0, errmsg: `Unrecognized pipeline stage name: '${stageName}'`, code: 40324 };
|
|
970
|
+
}
|
|
946
971
|
if (stage.$match) rows = rows.filter((r) => this._match(r, stage.$match));
|
|
947
972
|
else if (stage.$count) rows = [{ [stage.$count]: rows.length }];
|
|
948
973
|
else if (stage.$limit) rows = rows.slice(0, stage.$limit);
|
|
@@ -972,7 +997,13 @@ class MongoServer {
|
|
|
972
997
|
const out = [];
|
|
973
998
|
for (const r of rows) {
|
|
974
999
|
const arr = getPath(r, field);
|
|
975
|
-
|
|
1000
|
+
// #282:非数组标量按单元素数组展开(保留文档),缺失/NULL 才按 preserve 处理
|
|
1001
|
+
if (!Array.isArray(arr)) {
|
|
1002
|
+
if (arr === undefined || arr === null) { if (preserve) out.push(cloneDoc(r)); continue; }
|
|
1003
|
+
out.push(cloneDoc(r));
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
if (arr.length === 0) {
|
|
976
1007
|
if (preserve) out.push(cloneDoc(r));
|
|
977
1008
|
continue;
|
|
978
1009
|
}
|
package/lib/mysql_server.js
CHANGED
|
@@ -283,7 +283,7 @@ function toMysqlErrno(e) {
|
|
|
283
283
|
function columnDefinition(column) {
|
|
284
284
|
const b = new PacketBuilder();
|
|
285
285
|
b.raw(encodeLenencString('def'));
|
|
286
|
-
b.raw(encodeLenencString(column.
|
|
286
|
+
b.raw(encodeLenencString(column.database || ''));
|
|
287
287
|
b.raw(encodeLenencString(column.table || ''));
|
|
288
288
|
b.raw(encodeLenencString(column.table || ''));
|
|
289
289
|
b.raw(encodeLenencString(column.name || ''));
|
|
@@ -292,12 +292,22 @@ function columnDefinition(column) {
|
|
|
292
292
|
b.int16(column.charset || CHARSET_UTF8);
|
|
293
293
|
b.int32(column.length || 1024);
|
|
294
294
|
b.byte(column.type !== undefined ? column.type : MYSQL_TYPE_VAR_STRING);
|
|
295
|
-
b.int16(0);
|
|
295
|
+
b.int16(column.flags || 0);
|
|
296
296
|
b.byte(0);
|
|
297
297
|
b.int16(0);
|
|
298
298
|
return b.build();
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
+
function columnFlags(def) {
|
|
302
|
+
if (!def) return 0;
|
|
303
|
+
let flags = 0;
|
|
304
|
+
if (def.required || def.primaryKey || def.primary_key || def.autoIncrement) flags |= 0x0001; // NOT_NULL
|
|
305
|
+
if (def.primaryKey || def.primary_key) flags |= 0x0002; // PRI_KEY
|
|
306
|
+
if (def.autoIncrement) flags |= 0x0200; // AUTO_INCREMENT
|
|
307
|
+
if (def.unsigned) flags |= 0x0020; // UNSIGNED
|
|
308
|
+
return flags;
|
|
309
|
+
}
|
|
310
|
+
|
|
301
311
|
function columnTypeFromSchema(def) {
|
|
302
312
|
const type = def && def.type ? String(def.type).toLowerCase() : 'string';
|
|
303
313
|
if (type === 'bigint' || (def && def.intType === 'bigint')) return MYSQL_TYPE_LONGLONG;
|
|
@@ -345,7 +355,9 @@ function resultSetPacket(result, tableSchema, baseSeq, rawRow, status = SERVER_S
|
|
|
345
355
|
const col = {
|
|
346
356
|
name: String(name),
|
|
347
357
|
table: result.table || '',
|
|
358
|
+
database: result.database || '',
|
|
348
359
|
type: inferType(name, sample),
|
|
360
|
+
flags: columnFlags(tableSchema && tableSchema[name]),
|
|
349
361
|
length: 1024,
|
|
350
362
|
};
|
|
351
363
|
push(columnDefinition(col));
|
|
@@ -406,7 +418,7 @@ function binaryResultSetPacket(result, tableSchema, baseSeq, status = SERVER_STA
|
|
|
406
418
|
}
|
|
407
419
|
const t = inferType(cols[ci], sample);
|
|
408
420
|
types.push(t);
|
|
409
|
-
push(columnDefinition({ name: String(cols[ci]), table: result.table || '', type: t, length: 1024 }));
|
|
421
|
+
push(columnDefinition({ name: String(cols[ci]), table: result.table || '', database: result.database || '', type: t, flags: columnFlags(tableSchema && tableSchema[cols[ci]]), length: 1024 }));
|
|
410
422
|
}
|
|
411
423
|
push(eofPacket(status));
|
|
412
424
|
|
|
@@ -997,6 +1009,7 @@ class MysqlConnection {
|
|
|
997
1009
|
maxStatements: 1,
|
|
998
1010
|
session: this.session,
|
|
999
1011
|
});
|
|
1012
|
+
if (r && r.table) r.database = this.currentDb;
|
|
1000
1013
|
if (r.type === 'select' || r.type === 'showTables' || r.type === 'showDatabases' || r.type === 'describe'
|
|
1001
1014
|
|| r.type === 'showColumns' || r.type === 'showIndex' || r.type === 'showCreateTable'
|
|
1002
1015
|
|| r.type === 'showVariables' || r.type === 'showStatus' || r.type === 'showGrants' || r.type === 'showWarnings') {
|
package/lib/nedb_compat.js
CHANGED
|
@@ -191,9 +191,21 @@ function applyModifier(doc, update, opts = {}) {
|
|
|
191
191
|
} else if (op === '$push') {
|
|
192
192
|
for (const [k, v] of Object.entries(payload)) {
|
|
193
193
|
const cur = getPath(doc, k);
|
|
194
|
-
|
|
195
|
-
if (v && typeof v === 'object' && v.$each)
|
|
196
|
-
|
|
194
|
+
let arr = Array.isArray(cur) ? cur.slice() : [];
|
|
195
|
+
if (v && typeof v === 'object' && v.$each) {
|
|
196
|
+
const items = Array.isArray(v.$each) ? v.$each.slice() : [];
|
|
197
|
+
if (Number.isInteger(v.$position)) {
|
|
198
|
+
let pos = v.$position < 0 ? Math.max(arr.length + v.$position, 0) : Math.min(v.$position, arr.length);
|
|
199
|
+
arr.splice(pos, 0, ...items);
|
|
200
|
+
} else {
|
|
201
|
+
arr.push(...items);
|
|
202
|
+
}
|
|
203
|
+
if (Number.isInteger(v.$slice)) {
|
|
204
|
+
arr = v.$slice === 0 ? [] : (v.$slice > 0 ? arr.slice(0, v.$slice) : arr.slice(v.$slice));
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
arr.push(v);
|
|
208
|
+
}
|
|
197
209
|
setPath(doc, k, arr);
|
|
198
210
|
}
|
|
199
211
|
} else if (op === '$addToSet') {
|
package/lib/pg_server.js
CHANGED
|
@@ -384,7 +384,7 @@ class PgConnection {
|
|
|
384
384
|
await this._handleMessage(type, body);
|
|
385
385
|
}
|
|
386
386
|
} catch (e) {
|
|
387
|
-
this._send(buildErrorResponse('XX000', e && e.message ? e.message : String(e)));
|
|
387
|
+
this._send(buildErrorResponse((e && e.sqlState) || 'XX000', e && e.message ? e.message : String(e)));
|
|
388
388
|
this._send(buildReadyForQuery(this._rfqStatus()));
|
|
389
389
|
}
|
|
390
390
|
});
|
|
@@ -399,6 +399,8 @@ class PgConnection {
|
|
|
399
399
|
|
|
400
400
|
_handleStartup(body) {
|
|
401
401
|
const version = body.readInt32BE(4);
|
|
402
|
+
// #275:CancelRequest 无响应,直接关闭连接(此前被当成非法协议版本回 0A000)
|
|
403
|
+
if (version === 80877102) { this.socket.end(); return; }
|
|
402
404
|
if (version === 80877103) {
|
|
403
405
|
// SSLRequest: 拒绝后客户端重发 startup
|
|
404
406
|
this._send(Buffer.from([0x4e]));
|
|
@@ -558,6 +560,14 @@ class PgConnection {
|
|
|
558
560
|
values.push(fmt === 1 ? decodeBinaryParam(raw, pt) : body.toString('utf8', off, off + vlen));
|
|
559
561
|
off += vlen;
|
|
560
562
|
}
|
|
563
|
+
// #276:Bind 参数个数必须与 SQL 里的 $n 占位符数量一致
|
|
564
|
+
const maxParam = (String(stmt.sql).match(/\$(\d+)/g) || [])
|
|
565
|
+
.reduce((mx, tok) => Math.max(mx, Number(tok.slice(1)) || 0), 0);
|
|
566
|
+
if (nValues !== maxParam) {
|
|
567
|
+
const err = new Error(`bind message supplies ${nValues} parameters, but prepared statement requires ${maxParam}`);
|
|
568
|
+
err.sqlState = '08P01';
|
|
569
|
+
throw err;
|
|
570
|
+
}
|
|
561
571
|
this._portal.set(portal, { values, stmt });
|
|
562
572
|
this._send(buildBindComplete()); break;
|
|
563
573
|
}
|
package/lib/sqlite_compat.js
CHANGED
|
@@ -102,6 +102,8 @@ class Database {
|
|
|
102
102
|
|
|
103
103
|
exec(sql) {
|
|
104
104
|
if (typeof sql !== 'string') throw new TypeError('The "sql" argument must be a string');
|
|
105
|
+
// #297:空串与纯空白统一为 no-op(better-sqlite3 语义),不再一个抛错一个返回 []
|
|
106
|
+
if (sql.trim() === '') return this;
|
|
105
107
|
if (this.readonly && isWriteSql(sql)) {
|
|
106
108
|
throw new SqliteError('attempt to write a readonly database', 'SQLITE_READONLY');
|
|
107
109
|
}
|
package/lib/sqlite_worker.js
CHANGED
|
@@ -205,9 +205,21 @@ async function handleOp(op, args) {
|
|
|
205
205
|
case 'columns': {
|
|
206
206
|
const r = await executeStatement(args[0], args[1]);
|
|
207
207
|
const cols = r && r.type === 'select' && Array.isArray(r.columns) ? r.columns : [];
|
|
208
|
+
// #296:columns() 的 type 反映声明类型,而不是恒为 TEXT
|
|
209
|
+
let schema = null;
|
|
210
|
+
try {
|
|
211
|
+
if (r && r.table && typeof db.getTableSchema === 'function') schema = await db.getTableSchema(r.table);
|
|
212
|
+
} catch (e) { schema = null; }
|
|
213
|
+
const sqlTypeOf = (def) => {
|
|
214
|
+
const t = String((def && def.type) || 'string').toLowerCase();
|
|
215
|
+
if (t === 'integer' || t === 'int' || t === 'bigint' || t === 'boolean') return 'INTEGER';
|
|
216
|
+
if (t === 'number' || t === 'float' || t === 'double' || t === 'real' || t === 'decimal') return 'REAL';
|
|
217
|
+
if (t === 'object' || t === 'array') return 'TEXT';
|
|
218
|
+
return 'TEXT';
|
|
219
|
+
};
|
|
208
220
|
result = cols.map((name, i) => ({
|
|
209
221
|
name,
|
|
210
|
-
type:
|
|
222
|
+
type: sqlTypeOf(schema && schema[name]),
|
|
211
223
|
column: name,
|
|
212
224
|
table: r && r.table ? r.table : null,
|
|
213
225
|
database: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsql-neo",
|
|
3
|
-
"version": "6.8.
|
|
3
|
+
"version": "6.8.21",
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
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,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Regression tests for #271 #275 #276 #278 #283.
|
|
3
|
+
* node test/issue-271-283.test.js
|
|
4
|
+
*/
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const net = require('net');
|
|
7
|
+
const ROOT = path.join(__dirname, '..');
|
|
8
|
+
const { createMongoServer } = require(path.join(ROOT, 'lib', 'mongo_server.js'));
|
|
9
|
+
|
|
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
|
+
|
|
16
|
+
(async () => {
|
|
17
|
+
// #271
|
|
18
|
+
{
|
|
19
|
+
const mysql = (() => { try { return require(path.join(ROOT, 'node_modules', 'mysql2/promise')); } catch (e) { return null; } })();
|
|
20
|
+
if (mysql) {
|
|
21
|
+
const { createMysqlServer } = require(path.join(ROOT, 'lib', 'mysql_server.js'));
|
|
22
|
+
const srv = createMysqlServer({ port: 0, host: '127.0.0.1', dataDir: ':memory:', noAuth: true });
|
|
23
|
+
await new Promise((r) => srv.listen(r));
|
|
24
|
+
const c = await mysql.createConnection({ host: '127.0.0.1', port: srv.address.port, user: 'root', database: 'app' });
|
|
25
|
+
await c.query('CREATE TABLE t (id INT PRIMARY KEY AUTO_INCREMENT, v VARCHAR(10) NOT NULL)');
|
|
26
|
+
const [, f] = await c.query('SELECT id, v FROM t');
|
|
27
|
+
ok('#271 column flags expose PK/NOT NULL/AUTO_INCREMENT', (f[0].flags & 0x0002) !== 0 && (f[0].flags & 0x0200) !== 0 && (f[1].flags & 0x0001) !== 0, f.map(x => x.flags));
|
|
28
|
+
await c.end(); srv.close();
|
|
29
|
+
} else { console.log('[SKIP] MySQL flags (mysql2 not installed)'); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// #275 CancelRequest closes socket without ErrorResponse
|
|
33
|
+
{
|
|
34
|
+
const { createPgServer } = require(path.join(ROOT, 'lib', 'pg_server.js'));
|
|
35
|
+
const srv = createPgServer({ port: 0, host: '127.0.0.1', dataDir: ':memory:', noAuth: true });
|
|
36
|
+
await new Promise((r) => srv.listen(r));
|
|
37
|
+
const sock = net.connect(srv.address.port, '127.0.0.1');
|
|
38
|
+
await new Promise((r) => sock.on('connect', r));
|
|
39
|
+
const chunks = [];
|
|
40
|
+
let closed = false;
|
|
41
|
+
sock.on('data', (c) => chunks.push(c));
|
|
42
|
+
sock.on('close', () => { closed = true; });
|
|
43
|
+
const body = Buffer.alloc(12);
|
|
44
|
+
body.writeInt32BE(12, 0);
|
|
45
|
+
body.writeInt32BE(80877102, 4);
|
|
46
|
+
body.writeInt32BE(1234, 8);
|
|
47
|
+
sock.write(body);
|
|
48
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
49
|
+
ok('#275 CancelRequest closes without response', closed && chunks.length === 0, { closed, bytes: Buffer.concat(chunks).toString('hex') });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// #276 Bind parameter count mismatch (直接驱动协议层,pg 客户端会在本地拦截)
|
|
53
|
+
{
|
|
54
|
+
const { PgConnection } = require(path.join(ROOT, 'lib', 'pg_server.js'));
|
|
55
|
+
const conn = Object.create(PgConnection.prototype);
|
|
56
|
+
conn._prepared = new Map([['', { sql: 'SELECT $1::int', paramTypes: [23] }]]);
|
|
57
|
+
conn._portal = new Map();
|
|
58
|
+
conn.socket = { write() {} };
|
|
59
|
+
const body = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]);
|
|
60
|
+
let code = null;
|
|
61
|
+
try { await conn._handleMessage(0x42, body); } catch (e) { code = e.sqlState; }
|
|
62
|
+
ok('#276 bind param count mismatch -> 08P01', code === '08P01', code);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// #283 unknown aggregate stage
|
|
66
|
+
{
|
|
67
|
+
const mongo = createMongoServer({ dataDir: ':memory:' });
|
|
68
|
+
await mongo._dispatch('insert', { insert: 'c', documents: [{ a: 1 }], $db: 'test' });
|
|
69
|
+
const r = await mongo._dispatch('aggregate', { aggregate: 'c', pipeline: [{ $addFields: { b: 2 } }], cursor: {}, $db: 'test' });
|
|
70
|
+
ok('#283 unknown pipeline stage errors', r.ok === 0 && r.code === 40324, r);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// #278 batchSize + getMore
|
|
74
|
+
{
|
|
75
|
+
const mongo = createMongoServer({ dataDir: ':memory:' });
|
|
76
|
+
await mongo._dispatch('insert', { insert: 'c', documents: [{ n: 1 }, { n: 2 }, { n: 3 }, { n: 4 }, { n: 5 }], $db: 'test' });
|
|
77
|
+
const first = await mongo._dispatch('find', { find: 'c', filter: {}, batchSize: 2, $db: 'test' });
|
|
78
|
+
const id = first.cursor.id.$long;
|
|
79
|
+
ok('#278 find honors batchSize', first.cursor.firstBatch.length === 2 && id !== 0, first.cursor);
|
|
80
|
+
const more = await mongo._dispatch('getMore', { getMore: { $long: id }, collection: 'c', batchSize: 2, $db: 'test' });
|
|
81
|
+
ok('#278 getMore returns remaining rows', more.cursor.nextBatch.length === 2 && more.cursor.nextBatch[0].n === 3, more.cursor);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
85
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
86
|
+
})().catch((e) => { console.error('FATAL', e); process.exit(1); });
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Regression tests for #279 #282 #296 #297 #306.
|
|
3
|
+
* node test/issue-279-306.test.js
|
|
4
|
+
*/
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const ROOT = path.join(__dirname, '..');
|
|
7
|
+
const SqliteDatabase = require(path.join(ROOT, 'lib', 'sqlite_compat.js'));
|
|
8
|
+
const { createMongoServer } = require(path.join(ROOT, 'lib', 'mongo_server.js'));
|
|
9
|
+
|
|
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
|
+
|
|
16
|
+
(async () => {
|
|
17
|
+
// #296
|
|
18
|
+
{
|
|
19
|
+
const db = new SqliteDatabase(':memory:');
|
|
20
|
+
db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT, score REAL)');
|
|
21
|
+
const cols = db.prepare('SELECT * FROM t').columns();
|
|
22
|
+
const byName = Object.fromEntries(cols.map(c => [c.name, c.type]));
|
|
23
|
+
ok('#296 sqlite columns() reports declared types', byName.id === 'INTEGER' && byName.name === 'TEXT' && byName.score === 'REAL', byName);
|
|
24
|
+
db.close();
|
|
25
|
+
}
|
|
26
|
+
// #297
|
|
27
|
+
{
|
|
28
|
+
const db = new SqliteDatabase(':memory:');
|
|
29
|
+
let e1 = null, e2 = null;
|
|
30
|
+
try { db.exec(''); } catch (e) { e1 = e.message; }
|
|
31
|
+
try { db.exec(' \n '); } catch (e) { e2 = e.message; }
|
|
32
|
+
ok('#297 empty and whitespace exec are both no-op', e1 === null && e2 === null, { e1, e2 });
|
|
33
|
+
db.close();
|
|
34
|
+
}
|
|
35
|
+
// #306
|
|
36
|
+
{
|
|
37
|
+
const mysql = (() => { try { return require(path.join(ROOT, 'node_modules', 'mysql2/promise')); } catch (e) { return null; } })();
|
|
38
|
+
if (mysql) {
|
|
39
|
+
const { createMysqlServer } = require(path.join(ROOT, 'lib', 'mysql_server.js'));
|
|
40
|
+
const srv = createMysqlServer({ port: 0, host: '127.0.0.1', dataDir: ':memory:', noAuth: true });
|
|
41
|
+
await new Promise((r) => srv.listen(r));
|
|
42
|
+
const conn = await mysql.createConnection({ host: '127.0.0.1', port: srv.address.port, user: 'root', database: 'app' });
|
|
43
|
+
await conn.query('CREATE TABLE t (id INT)');
|
|
44
|
+
const [, fields] = await conn.query('SELECT id FROM t');
|
|
45
|
+
ok('#306 ColumnDefinition schema is database name', fields[0].schema === 'app' && fields[0].table === 't', { schema: fields[0].schema, table: fields[0].table });
|
|
46
|
+
await conn.end();
|
|
47
|
+
srv.close();
|
|
48
|
+
} else {
|
|
49
|
+
console.log('[SKIP] MySQL column schema (mysql2 not installed)');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// #279
|
|
53
|
+
{
|
|
54
|
+
const mongo = createMongoServer({ dataDir: ':memory:' });
|
|
55
|
+
const d = (cmd, doc) => mongo._dispatch(cmd, doc);
|
|
56
|
+
await d('insert', { insert: 'c', documents: [{ _id: 1, tags: ['a', 'b'] }], $db: 'test' });
|
|
57
|
+
await d('update', {
|
|
58
|
+
update: 'c', $db: 'test',
|
|
59
|
+
updates: [{ q: { _id: 1 }, u: { $push: { tags: { $each: ['x', 'y'], $position: 1, $slice: 3 } } } }],
|
|
60
|
+
});
|
|
61
|
+
const r = await d('find', { find: 'c', filter: { _id: 1 }, $db: 'test' });
|
|
62
|
+
const tags = r.cursor.firstBatch[0].tags;
|
|
63
|
+
ok('#279 $push honors $position and $slice', JSON.stringify(tags) === JSON.stringify(['a', 'x', 'y']), tags);
|
|
64
|
+
}
|
|
65
|
+
// #282
|
|
66
|
+
{
|
|
67
|
+
const mongo = createMongoServer({ dataDir: ':memory:' });
|
|
68
|
+
const d = (cmd, doc) => mongo._dispatch(cmd, doc);
|
|
69
|
+
await d('insert', { insert: 'u', documents: [{ _id: 1, b: 2 }], $db: 'test' });
|
|
70
|
+
const r = await d('aggregate', { aggregate: 'u', pipeline: [{ $unwind: '$b' }], cursor: {}, $db: 'test' });
|
|
71
|
+
const batch = r.cursor.firstBatch;
|
|
72
|
+
ok('#282 $unwind keeps scalar field document', batch.length === 1 && batch[0].b === 2, batch);
|
|
73
|
+
}
|
|
74
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
75
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
76
|
+
})().catch((e) => { console.error('FATAL', e); process.exit(1); });
|