jsql-neo 6.8.6 → 6.8.7
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/cache.js +6 -0
- package/lib/date-types.js +23 -15
- package/lib/redis_server.js +6 -0
- package/lib/sql.js +16 -0
- package/package.json +3 -3
- package/test/issue-238-241.test.js +65 -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.7** — 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/cache.js
CHANGED
|
@@ -41,6 +41,12 @@ class Cache {
|
|
|
41
41
|
const p = String(pattern);
|
|
42
42
|
for (let i = 0; i < p.length; i++) {
|
|
43
43
|
const c = p[i];
|
|
44
|
+
// #241:反斜杠转义下一个字符,按字面量匹配
|
|
45
|
+
if (c === '\\' && i + 1 < p.length) {
|
|
46
|
+
i++;
|
|
47
|
+
src += p[i].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
44
50
|
if (c === '*') { src += '.*'; continue; }
|
|
45
51
|
if (c === '?') { src += '.'; continue; }
|
|
46
52
|
if (c === '[') {
|
package/lib/date-types.js
CHANGED
|
@@ -49,6 +49,13 @@ function validateDateType(value, type, fieldName) {
|
|
|
49
49
|
|
|
50
50
|
function pad2(n) { return String(n).padStart(2, '0'); }
|
|
51
51
|
|
|
52
|
+
// #239:Date.UTC 把 0-99 年当成 1900+y,显式 setUTCFullYear 才能支持 0001-0099
|
|
53
|
+
function utcDate(y, mo, day, h = 0, mi = 0, sec = 0, ms = 0) {
|
|
54
|
+
const d = new Date(Date.UTC(2000, mo, day, h, mi, sec, ms));
|
|
55
|
+
d.setUTCFullYear(y);
|
|
56
|
+
return d;
|
|
57
|
+
}
|
|
58
|
+
|
|
52
59
|
/**
|
|
53
60
|
* 解析 ISO-8601 字符串尾部残余部分里的时区标记,返回「相对 UTC 的分钟偏移」。
|
|
54
61
|
* 输入形如 'Z'、'z'、'+08:00'、'-0500'、'.500Z'、' +02:00'。
|
|
@@ -109,7 +116,7 @@ function parseToUtcMs(str) {
|
|
|
109
116
|
// 「溢出归一」行为(→ 3 月 1 日),与改动前 new Date(...) 的宽松解析一致。
|
|
110
117
|
if (mo < 1 || mo > 12 || day < 1 || day > 31) return null;
|
|
111
118
|
if (h > 23 || mi > 59 || sec > 59) return null;
|
|
112
|
-
let ms =
|
|
119
|
+
let ms = utcDate(y, mo - 1, day, h, mi, sec, frac).getTime();
|
|
113
120
|
const rest = m[8] === undefined ? '' : m[8];
|
|
114
121
|
if (rest !== '') {
|
|
115
122
|
const tz = parseIsoTimezone(rest);
|
|
@@ -139,7 +146,7 @@ function validateDate(value, fieldName) {
|
|
|
139
146
|
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) {
|
|
140
147
|
const m = s.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
141
148
|
const y = parseInt(m[1]), mo = parseInt(m[2]), d = parseInt(m[3]);
|
|
142
|
-
const dt =
|
|
149
|
+
const dt = utcDate(y, mo - 1, d);
|
|
143
150
|
if (dt.getUTCFullYear() === y && dt.getUTCMonth() === mo - 1 && dt.getUTCDate() === d) return s;
|
|
144
151
|
}
|
|
145
152
|
const d = parseDateString(s);
|
|
@@ -154,21 +161,21 @@ function parseDateString(str) {
|
|
|
154
161
|
let m = str.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
155
162
|
if (m) {
|
|
156
163
|
const y = parseInt(m[1]), mo = parseInt(m[2]), d = parseInt(m[3]);
|
|
157
|
-
const dt =
|
|
164
|
+
const dt = utcDate(y, mo - 1, d);
|
|
158
165
|
if (dt.getUTCFullYear() === y && dt.getUTCMonth() === mo - 1 && dt.getUTCDate() === d) return dt;
|
|
159
166
|
}
|
|
160
167
|
// YYYY/MM/DD
|
|
161
168
|
m = str.match(/^(\d{4})\/(\d{2})\/(\d{2})$/);
|
|
162
169
|
if (m) {
|
|
163
170
|
const y = parseInt(m[1]), mo = parseInt(m[2]), d = parseInt(m[3]);
|
|
164
|
-
const dt =
|
|
171
|
+
const dt = utcDate(y, mo - 1, d);
|
|
165
172
|
if (dt.getUTCFullYear() === y && dt.getUTCMonth() === mo - 1 && dt.getUTCDate() === d) return dt;
|
|
166
173
|
}
|
|
167
174
|
// MM/DD/YYYY
|
|
168
175
|
m = str.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
|
|
169
176
|
if (m) {
|
|
170
177
|
const y = parseInt(m[3]), mo = parseInt(m[1]), d = parseInt(m[2]);
|
|
171
|
-
const dt =
|
|
178
|
+
const dt = utcDate(y, mo - 1, d);
|
|
172
179
|
if (dt.getUTCFullYear() === y && dt.getUTCMonth() === mo - 1 && dt.getUTCDate() === d) return dt;
|
|
173
180
|
}
|
|
174
181
|
// 通用路径:自己解析部件 + 时区标记;不回落 new Date(str)(那会用本地时区)
|
|
@@ -213,7 +220,7 @@ function validateDateTime(value, fieldName) {
|
|
|
213
220
|
if (dm && tm) {
|
|
214
221
|
const y = parseInt(dm[1]), mo = parseInt(dm[2]), d = parseInt(dm[3]);
|
|
215
222
|
const h = parseInt(tm[1]), mi = parseInt(tm[2]), s = parseInt(tm[3]);
|
|
216
|
-
const dt =
|
|
223
|
+
const dt = utcDate(y, mo - 1, d);
|
|
217
224
|
if (dt.getUTCFullYear() === y && dt.getUTCMonth() === mo - 1 && dt.getUTCDate() === d &&
|
|
218
225
|
h >= 0 && h < 24 && mi >= 0 && mi < 60 && s >= 0 && s < 60) {
|
|
219
226
|
// 带 Z / ±HH:MM 时区标记:先换算成绝对时刻,再以 UTC 墙上时间落库。
|
|
@@ -221,7 +228,7 @@ function validateDateTime(value, fieldName) {
|
|
|
221
228
|
// 二者因此在 UTC 字面量上完全等价(#75 round-trip)。
|
|
222
229
|
const tz = parseIsoTimezone(value.slice(isoMatch[0].length));
|
|
223
230
|
if (tz !== null) {
|
|
224
|
-
const ms =
|
|
231
|
+
const ms = utcDate(y, mo - 1, d, h, mi, s).getTime() + msPart - tz * 60000;
|
|
225
232
|
return toUtcDateTimeStringMs(new Date(ms));
|
|
226
233
|
}
|
|
227
234
|
return datePart + ' ' + timePart + (msPart ? '.' + String(msPart).padStart(3, '0') : '');
|
|
@@ -239,7 +246,7 @@ function validateDateTime(value, fieldName) {
|
|
|
239
246
|
if (dm && tm) {
|
|
240
247
|
const y = parseInt(dm[1]), mo = parseInt(dm[2]), d = parseInt(dm[3]);
|
|
241
248
|
const h = parseInt(tm[1]), mi = parseInt(tm[2]), s = parseInt(tm[3]);
|
|
242
|
-
const dt =
|
|
249
|
+
const dt = utcDate(y, mo - 1, d);
|
|
243
250
|
if (dt.getUTCFullYear() === y && dt.getUTCMonth() === mo - 1 && dt.getUTCDate() === d &&
|
|
244
251
|
h >= 0 && h < 24 && mi >= 0 && mi < 60 && s >= 0 && s < 60) {
|
|
245
252
|
return value; // 无时区 → 即 UTC 墙上时间,原样落库
|
|
@@ -340,13 +347,14 @@ function formatDate(value, format = 'YYYY-MM-DD') {
|
|
|
340
347
|
if (isNaN(d.getTime())) return String(value);
|
|
341
348
|
|
|
342
349
|
const pad = n => String(n).padStart(2, '0');
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
.replace(
|
|
346
|
-
.replace(
|
|
347
|
-
.replace(
|
|
348
|
-
.replace(
|
|
349
|
-
.replace(
|
|
350
|
+
// #238:同一个 token 可能出现多次,必须全局替换
|
|
351
|
+
return String(format)
|
|
352
|
+
.replace(/YYYY/g, String(d.getUTCFullYear()).padStart(4, '0'))
|
|
353
|
+
.replace(/MM/g, pad(d.getUTCMonth() + 1))
|
|
354
|
+
.replace(/DD/g, pad(d.getUTCDate()))
|
|
355
|
+
.replace(/HH/g, pad(d.getUTCHours()))
|
|
356
|
+
.replace(/mm/g, pad(d.getUTCMinutes()))
|
|
357
|
+
.replace(/ss/g, pad(d.getUTCSeconds()));
|
|
350
358
|
}
|
|
351
359
|
|
|
352
360
|
module.exports = { validateDateType, now, formatDate };
|
package/lib/redis_server.js
CHANGED
|
@@ -45,6 +45,12 @@ function globToRegex(pattern) {
|
|
|
45
45
|
let src = '^';
|
|
46
46
|
for (let i = 0; i < p.length; i++) {
|
|
47
47
|
const c = p[i];
|
|
48
|
+
// #241:反斜杠转义下一个字符,按字面量匹配
|
|
49
|
+
if (c === '\\' && i + 1 < p.length) {
|
|
50
|
+
i++;
|
|
51
|
+
src += p[i].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
48
54
|
if (c === '*') { src += '.*'; continue; }
|
|
49
55
|
if (c === '?') { src += '.'; continue; }
|
|
50
56
|
if (c === '[') {
|
package/lib/sql.js
CHANGED
|
@@ -10309,7 +10309,23 @@ async function inferColumnTypes(engine, stmt, r) {
|
|
|
10309
10309
|
? stmt.from.tables[0].table : null;
|
|
10310
10310
|
if (t && engine && typeof engine.getTableSchema === 'function') schema = await engine.getTableSchema(t);
|
|
10311
10311
|
} catch (e) { schema = null; }
|
|
10312
|
+
const defs = (stmt && Array.isArray(stmt.columns)) ? stmt.columns : [];
|
|
10313
|
+
const aggType = (fn) => String(fn).toUpperCase() === 'COUNT' ? 'INT' : 'FLOAT';
|
|
10312
10314
|
return r.columns.map((name) => {
|
|
10315
|
+
// #240:先按输出列找到对应表达式;聚合列按聚合函数类型,不能拿别名回查表列
|
|
10316
|
+
const c = defs.find((d) => scalarColumnName(d) === name);
|
|
10317
|
+
if (c) {
|
|
10318
|
+
if (c.aggregate) return aggType(c.aggregate);
|
|
10319
|
+
if (c.scalar && containsAggregateNode(c.scalar)) return 'FLOAT';
|
|
10320
|
+
if (c.scalar && c.scalar.type === 'column' && schema && schema[c.scalar.name]) {
|
|
10321
|
+
return sqlTypeName(schema[c.scalar.name].type).toUpperCase();
|
|
10322
|
+
}
|
|
10323
|
+
if (typeof c.expr === 'string' && c.expr !== '*' && (!c.alias || c.alias === c.expr)) {
|
|
10324
|
+
const def = schema && schema[c.expr];
|
|
10325
|
+
if (def && def.type) return sqlTypeName(def.type).toUpperCase();
|
|
10326
|
+
}
|
|
10327
|
+
return null;
|
|
10328
|
+
}
|
|
10313
10329
|
const def = schema && schema[name];
|
|
10314
10330
|
return def && def.type ? sqlTypeName(def.type).toUpperCase() : null;
|
|
10315
10331
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsql-neo",
|
|
3
|
-
"version": "6.8.
|
|
3
|
+
"version": "6.8.7",
|
|
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/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",
|
|
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",
|
|
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/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",
|
|
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",
|
|
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,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Regression tests for issues #238-#241.
|
|
3
|
+
* node test/issue-238-241.test.js
|
|
4
|
+
*/
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const ROOT = path.join(__dirname, '..');
|
|
7
|
+
const { formatDate, validateDateType } = require(path.join(ROOT, 'lib', 'date-types.js'));
|
|
8
|
+
const Cache = require(path.join(ROOT, 'lib', 'cache.js'));
|
|
9
|
+
const { JSQL } = require(path.join(ROOT, 'index.js'));
|
|
10
|
+
|
|
11
|
+
let passed = 0, failed = 0;
|
|
12
|
+
function ok(name, cond, extra) {
|
|
13
|
+
if (cond) { passed++; console.log('[OK]', name); }
|
|
14
|
+
else { failed++; console.log('[FAIL]', name, extra !== undefined ? '→ ' + JSON.stringify(extra) : ''); }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
(async () => {
|
|
18
|
+
// #238
|
|
19
|
+
const f1 = formatDate('2024-01-02 13:45:59', 'YYYY-MM-DD HH:mm:ss HH');
|
|
20
|
+
const f2 = formatDate('2024-01-02', 'YYYY YYYY');
|
|
21
|
+
ok('#238 repeated format tokens all replaced', f1 === '2024-01-02 13:45:59 13' && f2 === '2024 2024', { f1, f2 });
|
|
22
|
+
|
|
23
|
+
// #239
|
|
24
|
+
const dates = ['0099-01-02', '0050-06-15', '0001-12-31'];
|
|
25
|
+
let allOk = true;
|
|
26
|
+
for (const s of dates) {
|
|
27
|
+
try { if (validateDateType(s, 'date', 'd') !== s) allOk = false; } catch (e) { allOk = false; }
|
|
28
|
+
}
|
|
29
|
+
ok('#239 years 0001-0099 are valid', allOk);
|
|
30
|
+
ok('#239 formatDate keeps low year', formatDate('0099-01-02', 'YYYY') === '0099', formatDate('0099-01-02', 'YYYY'));
|
|
31
|
+
|
|
32
|
+
// #241
|
|
33
|
+
{
|
|
34
|
+
const c = new Cache();
|
|
35
|
+
['a*', 'ab', 'a?'].forEach(k => c.set(k, 1));
|
|
36
|
+
const star = c.keys('a\\*');
|
|
37
|
+
const qm = c.keys('a\\?');
|
|
38
|
+
ok('#241 Cache.keys glob backslash escape', JSON.stringify(star) === JSON.stringify(['a*']) && JSON.stringify(qm) === JSON.stringify(['a?']), { star, qm });
|
|
39
|
+
c.close();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// #240
|
|
43
|
+
{
|
|
44
|
+
const db = new JSQL();
|
|
45
|
+
await db.start();
|
|
46
|
+
await db.createTable('t', {
|
|
47
|
+
id: { type: 'integer', primaryKey: true },
|
|
48
|
+
v: { type: 'integer' },
|
|
49
|
+
s: { type: 'string' },
|
|
50
|
+
});
|
|
51
|
+
await db.insert('t', { id: 1, v: 10, s: 'aa' });
|
|
52
|
+
await db.insert('t', { id: 2, v: 20, s: 'bb' });
|
|
53
|
+
const sum = await db.query('SELECT SUM(v) AS s FROM t');
|
|
54
|
+
const avg = await db.query('SELECT AVG(v) AS v FROM t');
|
|
55
|
+
const count = await db.query('SELECT COUNT(*) AS c FROM t');
|
|
56
|
+
const plain = await db.query('SELECT s FROM t');
|
|
57
|
+
ok('#240 aggregate column types do not use alias', sum.columnTypes[0] !== 'VARCHAR(255)' && avg.columnTypes[0] !== 'INT', { sum: sum.columnTypes, avg: avg.columnTypes });
|
|
58
|
+
ok('#240 COUNT is INT', count.columnTypes[0] === 'INT', count.columnTypes);
|
|
59
|
+
ok('#240 plain string column type', plain.columnTypes[0] === 'VARCHAR(255)', plain.columnTypes);
|
|
60
|
+
await db.stop();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
64
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
65
|
+
})().catch((e) => { console.error('FATAL', e); process.exit(1); });
|