jsql-neo 6.8.18 → 6.8.20
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 +7 -1
- package/lib/mysql_server.js +26 -5
- package/lib/nedb_compat.js +15 -3
- package/lib/pg_server.js +6 -3
- package/lib/sqlite_compat.js +2 -0
- package/lib/sqlite_worker.js +13 -1
- package/package.json +3 -3
- package/test/issue-272-311.test.js +68 -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.20** — 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
|
@@ -972,7 +972,13 @@ class MongoServer {
|
|
|
972
972
|
const out = [];
|
|
973
973
|
for (const r of rows) {
|
|
974
974
|
const arr = getPath(r, field);
|
|
975
|
-
|
|
975
|
+
// #282:非数组标量按单元素数组展开(保留文档),缺失/NULL 才按 preserve 处理
|
|
976
|
+
if (!Array.isArray(arr)) {
|
|
977
|
+
if (arr === undefined || arr === null) { if (preserve) out.push(cloneDoc(r)); continue; }
|
|
978
|
+
out.push(cloneDoc(r));
|
|
979
|
+
continue;
|
|
980
|
+
}
|
|
981
|
+
if (arr.length === 0) {
|
|
976
982
|
if (preserve) out.push(cloneDoc(r));
|
|
977
983
|
continue;
|
|
978
984
|
}
|
package/lib/mysql_server.js
CHANGED
|
@@ -211,7 +211,16 @@ function eofPacket(status = SERVER_STATUS_AUTOCOMMIT) {
|
|
|
211
211
|
return b.build();
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
function
|
|
214
|
+
function mysqlSqlState(errno) {
|
|
215
|
+
return ({
|
|
216
|
+
1048: '23000', 1050: '42S01', 1054: '42S22', 1062: '23000',
|
|
217
|
+
1064: '42000', 1102: '42000', 1136: '21S01', 1146: '42S02',
|
|
218
|
+
1264: '22003', 1406: '22001', 3819: 'HY000',
|
|
219
|
+
})[errno] || 'HY000';
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function errPacket(errno, message, sqlState) {
|
|
223
|
+
if (!sqlState) sqlState = mysqlSqlState(errno);
|
|
215
224
|
const b = new PacketBuilder();
|
|
216
225
|
b.byte(0xff);
|
|
217
226
|
b.int16(errno);
|
|
@@ -224,6 +233,15 @@ function errPacket(errno, message, sqlState = 'HY000') {
|
|
|
224
233
|
function toMysqlErrno(e) {
|
|
225
234
|
if (e && typeof e.code === 'number') return e.code;
|
|
226
235
|
const m = e && e.message ? String(e.message).match(/^(ER_[A-Z_]+)/) : null;
|
|
236
|
+
// 引擎异常可能只有 message 没有 ER_ 前缀,补常见回退映射(#274)
|
|
237
|
+
const text = String((e && e.message) || '');
|
|
238
|
+
if (!m) {
|
|
239
|
+
if (/no such table|table .*(doesn't|does not) exist/i.test(text)) return 1146;
|
|
240
|
+
if (/no such column|unknown column/i.test(text)) return 1054;
|
|
241
|
+
if (/duplicate entry|unique constraint/i.test(text)) return 1062;
|
|
242
|
+
if (/cannot be null|not null constraint/i.test(text)) return 1048;
|
|
243
|
+
if (/syntax error|unexpected token|expected /i.test(text)) return 1064;
|
|
244
|
+
}
|
|
227
245
|
if (m) {
|
|
228
246
|
const known = {
|
|
229
247
|
ER_DUP_ENTRY: 1062,
|
|
@@ -265,7 +283,7 @@ function toMysqlErrno(e) {
|
|
|
265
283
|
function columnDefinition(column) {
|
|
266
284
|
const b = new PacketBuilder();
|
|
267
285
|
b.raw(encodeLenencString('def'));
|
|
268
|
-
b.raw(encodeLenencString(column.
|
|
286
|
+
b.raw(encodeLenencString(column.database || ''));
|
|
269
287
|
b.raw(encodeLenencString(column.table || ''));
|
|
270
288
|
b.raw(encodeLenencString(column.table || ''));
|
|
271
289
|
b.raw(encodeLenencString(column.name || ''));
|
|
@@ -327,6 +345,7 @@ function resultSetPacket(result, tableSchema, baseSeq, rawRow, status = SERVER_S
|
|
|
327
345
|
const col = {
|
|
328
346
|
name: String(name),
|
|
329
347
|
table: result.table || '',
|
|
348
|
+
database: result.database || '',
|
|
330
349
|
type: inferType(name, sample),
|
|
331
350
|
length: 1024,
|
|
332
351
|
};
|
|
@@ -388,7 +407,7 @@ function binaryResultSetPacket(result, tableSchema, baseSeq, status = SERVER_STA
|
|
|
388
407
|
}
|
|
389
408
|
const t = inferType(cols[ci], sample);
|
|
390
409
|
types.push(t);
|
|
391
|
-
push(columnDefinition({ name: String(cols[ci]), table: result.table || '', type: t, length: 1024 }));
|
|
410
|
+
push(columnDefinition({ name: String(cols[ci]), table: result.table || '', database: result.database || '', type: t, length: 1024 }));
|
|
392
411
|
}
|
|
393
412
|
push(eofPacket(status));
|
|
394
413
|
|
|
@@ -565,8 +584,9 @@ class MysqlConnection {
|
|
|
565
584
|
case 0x02: { // COM_INIT_DB
|
|
566
585
|
const db = body.toString('utf8');
|
|
567
586
|
if (!this.server._safeDbName(db)) {
|
|
568
|
-
|
|
569
|
-
|
|
587
|
+
// #272:非法库名回 ERR_Packet,不能直接销毁连接
|
|
588
|
+
this._send(errPacket(1102, `Incorrect database name '${db}'`));
|
|
589
|
+
break;
|
|
570
590
|
}
|
|
571
591
|
this.server._switchDb(this, db)
|
|
572
592
|
.then(() => this._send(okPacket()))
|
|
@@ -978,6 +998,7 @@ class MysqlConnection {
|
|
|
978
998
|
maxStatements: 1,
|
|
979
999
|
session: this.session,
|
|
980
1000
|
});
|
|
1001
|
+
if (r && r.table) r.database = this.currentDb;
|
|
981
1002
|
if (r.type === 'select' || r.type === 'showTables' || r.type === 'showDatabases' || r.type === 'describe'
|
|
982
1003
|
|| r.type === 'showColumns' || r.type === 'showIndex' || r.type === 'showCreateTable'
|
|
983
1004
|
|| 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
|
@@ -160,7 +160,7 @@ function buildRowDescription(columns, types) {
|
|
|
160
160
|
p.i32(0); // table oid
|
|
161
161
|
p.i16(0); // column attnum
|
|
162
162
|
p.i32(pgTypeOid(types[i]));
|
|
163
|
-
p.i16(types[i] === 'integer' ? 4 : (types[i] === 'bigint' ? 8 : -1)); // typlen
|
|
163
|
+
p.i16(types[i] === 'integer' ? 4 : (types[i] === 'bigint' ? 8 : (types[i] === 'boolean' ? 1 : -1))); // typlen
|
|
164
164
|
p.i32(-1); // typmod
|
|
165
165
|
p.i16(0); // format code (text)
|
|
166
166
|
}
|
|
@@ -616,7 +616,8 @@ class PgConnection {
|
|
|
616
616
|
if (kind === 0x53) { // 'S' statement
|
|
617
617
|
const stmt = this._prepared.get(name);
|
|
618
618
|
if (!stmt) throw new Error(`prepared statement "${name}" does not exist`);
|
|
619
|
-
|
|
619
|
+
// #309:无参语句 ParameterDescription 应为 paramCount=0
|
|
620
|
+
this._send(buildParameterDesc(stmt.paramTypes || []));
|
|
620
621
|
const cols = this._describeCols(stmt.sql);
|
|
621
622
|
if (cols && cols.length > 0) {
|
|
622
623
|
this._send(buildRowDescription(cols.columns, cols.types));
|
|
@@ -776,7 +777,9 @@ class PgConnection {
|
|
|
776
777
|
this._txAborted = false;
|
|
777
778
|
this._send(buildCommandComplete(String(res.type).toUpperCase()));
|
|
778
779
|
} else if (res.type === 'createTable' || res.type === 'dropTable' || res.type === 'createDatabase' || res.type === 'dropDatabase') {
|
|
779
|
-
|
|
780
|
+
// #308:DDL CommandComplete tag 用真实语句类型
|
|
781
|
+
const tags = { createTable: 'CREATE TABLE', dropTable: 'DROP TABLE', createDatabase: 'CREATE DATABASE', dropDatabase: 'DROP DATABASE' };
|
|
782
|
+
this._send(buildCommandComplete(tags[res.type] || 'OK'));
|
|
780
783
|
} else if (res.type === 'showTables' || res.type === 'showDatabases' || res.type === 'showColumns') {
|
|
781
784
|
const types = (res.columns || []).map(() => 'string');
|
|
782
785
|
this._send(buildRowDescription(res.columns || [], types));
|
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.20",
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
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,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Regression tests for #272 #274 #308 #309 #311.
|
|
3
|
+
* node test/issue-272-311.test.js
|
|
4
|
+
*/
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const ROOT = path.join(__dirname, '..');
|
|
7
|
+
|
|
8
|
+
let passed = 0, failed = 0;
|
|
9
|
+
function ok(name, cond, extra) {
|
|
10
|
+
if (cond) { passed++; console.log('[OK]', name); }
|
|
11
|
+
else { failed++; console.log('[FAIL]', name, extra !== undefined ? '→ ' + JSON.stringify(extra) : ''); }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
(async () => {
|
|
15
|
+
const mysql = (() => { try { return require(path.join(ROOT, 'node_modules', 'mysql2/promise')); } catch (e) { return null; } })();
|
|
16
|
+
if (mysql) {
|
|
17
|
+
const { createMysqlServer } = require(path.join(ROOT, 'lib', 'mysql_server.js'));
|
|
18
|
+
const srv = createMysqlServer({ port: 0, host: '127.0.0.1', dataDir: ':memory:', noAuth: true });
|
|
19
|
+
await new Promise((r) => srv.listen(r));
|
|
20
|
+
const conn = await mysql.createConnection({ host: '127.0.0.1', port: srv.address.port, user: 'root', database: 'app' });
|
|
21
|
+
// #274
|
|
22
|
+
let missing = null;
|
|
23
|
+
try { await conn.query('SELECT * FROM no_such_table'); } catch (e) { missing = e; }
|
|
24
|
+
ok('#274 missing table errno/sqlstate', missing && missing.errno === 1146 && missing.sqlState === '42S02', missing && { errno: missing.errno, state: missing.sqlState });
|
|
25
|
+
// #272
|
|
26
|
+
try { await conn.changeUser({ database: 'bad/name' }); } catch (e) { /* expected */ }
|
|
27
|
+
let alive = null;
|
|
28
|
+
try { await conn.query('SELECT 1 AS x'); alive = 1; } catch (e) { alive = e.message; }
|
|
29
|
+
ok('#272 invalid COM_INIT_DB keeps connection alive', alive === 1, alive);
|
|
30
|
+
await conn.end();
|
|
31
|
+
srv.close();
|
|
32
|
+
} else {
|
|
33
|
+
console.log('[SKIP] MySQL protocol tests (mysql2 not installed)');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// #311 boolean typlen = 1
|
|
37
|
+
{
|
|
38
|
+
const { buildRowDescription, buildParameterDesc } = require(path.join(ROOT, 'lib', 'pg_server.js'));
|
|
39
|
+
const buf = buildRowDescription(['b'], ['boolean']);
|
|
40
|
+
// frame: type(1)+len(4)+count(2)+name('b'+nul=2)+tableoid(4)+attnum(2)+typeoid(4)+typlen(2)
|
|
41
|
+
const typlen = buf.readInt16BE(5 + 2 + 2 + 4 + 2 + 4);
|
|
42
|
+
ok('#311 PG boolean typlen is 1', typlen === 1, typlen);
|
|
43
|
+
// #309 builder emits paramCount=0 for empty list
|
|
44
|
+
const pd = buildParameterDesc([]);
|
|
45
|
+
ok('#309 ParameterDescription has zero params', pd.readInt16BE(5) === 0, pd.readInt16BE(5));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// #308 DDL tag (pg driver exposes only the leading word, so check it is not "OK")
|
|
49
|
+
{
|
|
50
|
+
const { Client } = (() => { try { return require(path.join(ROOT, 'node_modules', 'pg')); } catch (e) { return {}; } })();
|
|
51
|
+
if (Client) {
|
|
52
|
+
const { createPgServer } = require(path.join(ROOT, 'lib', 'pg_server.js'));
|
|
53
|
+
const srv = createPgServer({ port: 0, host: '127.0.0.1', dataDir: ':memory:', noAuth: true });
|
|
54
|
+
await new Promise((r) => srv.listen(r));
|
|
55
|
+
const c = new Client({ host: '127.0.0.1', port: srv.address.port, user: 'root', database: 'app' });
|
|
56
|
+
await c.connect();
|
|
57
|
+
const r = await c.query('CREATE TABLE t (id INT)');
|
|
58
|
+
ok('#308 PG DDL CommandComplete tag is statement type', r.command === 'CREATE', r.command);
|
|
59
|
+
await c.end();
|
|
60
|
+
srv.close();
|
|
61
|
+
} else {
|
|
62
|
+
console.log('[SKIP] PG DDL tag (pg not installed)');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
67
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
68
|
+
})().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); });
|