@maiyunnet/kebab 8.0.2 → 8.0.4
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/doc/kebab-rag.md +26 -26
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/sql.d.ts +1 -1
- package/lib/sql.js +19 -1
- package/package.json +1 -1
- package/sys/mod.js +19 -19
- package/sys/monitor/watchdog.js +10 -4
- package/sys/monitor.js +16 -2
package/doc/kebab-rag.md
CHANGED
|
@@ -1385,7 +1385,7 @@ index/variables/VER.md
|
|
|
1385
1385
|
|
|
1386
1386
|
# Variable: VER
|
|
1387
1387
|
|
|
1388
|
-
> `const` **VER**: `"8.0.
|
|
1388
|
+
> `const` **VER**: `"8.0.4"` = `'8.0.4'`
|
|
1389
1389
|
|
|
1390
1390
|
Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
|
|
1391
1391
|
|
|
@@ -12836,7 +12836,7 @@ Defined in: [lib/sql.ts:66](https://github.com/maiyunnet/kebab/blob/master/lib/s
|
|
|
12836
12836
|
|
|
12837
12837
|
> **append**(`sql`): `this`
|
|
12838
12838
|
|
|
12839
|
-
Defined in: [lib/sql.ts:
|
|
12839
|
+
Defined in: [lib/sql.ts:874](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L874)
|
|
12840
12840
|
|
|
12841
12841
|
在 sql 最后追加字符串
|
|
12842
12842
|
|
|
@@ -12856,7 +12856,7 @@ Defined in: [lib/sql.ts:860](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
12856
12856
|
|
|
12857
12857
|
> **by**(`c`, `d?`): `this`
|
|
12858
12858
|
|
|
12859
|
-
Defined in: [lib/sql.ts:
|
|
12859
|
+
Defined in: [lib/sql.ts:668](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L668)
|
|
12860
12860
|
|
|
12861
12861
|
ORDER BY
|
|
12862
12862
|
|
|
@@ -12884,7 +12884,7 @@ ORDER BY
|
|
|
12884
12884
|
|
|
12885
12885
|
> **copy**(`f?`, `opt?`): `Sql`
|
|
12886
12886
|
|
|
12887
|
-
Defined in: [lib/sql.ts:
|
|
12887
|
+
Defined in: [lib/sql.ts:736](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L736)
|
|
12888
12888
|
|
|
12889
12889
|
创建一个本对象的一个新的 sql 对象拷贝
|
|
12890
12890
|
|
|
@@ -12912,7 +12912,7 @@ Defined in: [lib/sql.ts:729](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
12912
12912
|
|
|
12913
12913
|
> **crossJoin**(`f`, `s?`, `suf?`, `pre?`): `this`
|
|
12914
12914
|
|
|
12915
|
-
Defined in: [lib/sql.ts:
|
|
12915
|
+
Defined in: [lib/sql.ts:423](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L423)
|
|
12916
12916
|
|
|
12917
12917
|
cross join 方法
|
|
12918
12918
|
|
|
@@ -12974,7 +12974,7 @@ Defined in: [lib/sql.ts:311](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
12974
12974
|
|
|
12975
12975
|
> **field**(`str`, `pre?`, `suf?`): `string`
|
|
12976
12976
|
|
|
12977
|
-
Defined in: [lib/sql.ts:
|
|
12977
|
+
Defined in: [lib/sql.ts:885](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L885)
|
|
12978
12978
|
|
|
12979
12979
|
对字段进行包裹
|
|
12980
12980
|
|
|
@@ -12982,7 +12982,7 @@ Defined in: [lib/sql.ts:871](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
12982
12982
|
|
|
12983
12983
|
##### str
|
|
12984
12984
|
|
|
12985
|
-
`string` | `number` |
|
|
12985
|
+
`string` | `number` | \[`string`, `string`[]\]
|
|
12986
12986
|
|
|
12987
12987
|
##### pre?
|
|
12988
12988
|
|
|
@@ -13006,7 +13006,7 @@ Defined in: [lib/sql.ts:871](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
13006
13006
|
|
|
13007
13007
|
> **format**(`sql?`, `data?`): `string`
|
|
13008
13008
|
|
|
13009
|
-
Defined in: [lib/sql.ts:
|
|
13009
|
+
Defined in: [lib/sql.ts:864](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L864)
|
|
13010
13010
|
|
|
13011
13011
|
获取带 data 的 sql 语句
|
|
13012
13012
|
|
|
@@ -13030,7 +13030,7 @@ Defined in: [lib/sql.ts:850](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
13030
13030
|
|
|
13031
13031
|
> **fullJoin**(`f`, `s?`, `suf?`, `pre?`): `this`
|
|
13032
13032
|
|
|
13033
|
-
Defined in: [lib/sql.ts:
|
|
13033
|
+
Defined in: [lib/sql.ts:412](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L412)
|
|
13034
13034
|
|
|
13035
13035
|
full join 方法
|
|
13036
13036
|
|
|
@@ -13070,7 +13070,7 @@ ON 信息
|
|
|
13070
13070
|
|
|
13071
13071
|
> **getData**(): [`DbValue`](../../../index/type-aliases/DbValue.md)[]
|
|
13072
13072
|
|
|
13073
|
-
Defined in: [lib/sql.ts:
|
|
13073
|
+
Defined in: [lib/sql.ts:848](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L848)
|
|
13074
13074
|
|
|
13075
13075
|
获取全部 data
|
|
13076
13076
|
|
|
@@ -13084,7 +13084,7 @@ Defined in: [lib/sql.ts:834](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
13084
13084
|
|
|
13085
13085
|
> **getPre**(): `string`
|
|
13086
13086
|
|
|
13087
|
-
Defined in: [lib/sql.ts:
|
|
13087
|
+
Defined in: [lib/sql.ts:855](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L855)
|
|
13088
13088
|
|
|
13089
13089
|
获取定义的 pre
|
|
13090
13090
|
|
|
@@ -13098,7 +13098,7 @@ Defined in: [lib/sql.ts:841](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
13098
13098
|
|
|
13099
13099
|
> **getSql**(): `string`
|
|
13100
13100
|
|
|
13101
|
-
Defined in: [lib/sql.ts:
|
|
13101
|
+
Defined in: [lib/sql.ts:832](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L832)
|
|
13102
13102
|
|
|
13103
13103
|
获取 sql 语句
|
|
13104
13104
|
|
|
@@ -13112,7 +13112,7 @@ Defined in: [lib/sql.ts:818](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
13112
13112
|
|
|
13113
13113
|
> **group**(`c`): `this`
|
|
13114
13114
|
|
|
13115
|
-
Defined in: [lib/sql.ts:
|
|
13115
|
+
Defined in: [lib/sql.ts:692](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L692)
|
|
13116
13116
|
|
|
13117
13117
|
GROUP BY
|
|
13118
13118
|
|
|
@@ -13134,7 +13134,7 @@ GROUP BY
|
|
|
13134
13134
|
|
|
13135
13135
|
> **having**(`s?`): `this`
|
|
13136
13136
|
|
|
13137
|
-
Defined in: [lib/sql.ts:
|
|
13137
|
+
Defined in: [lib/sql.ts:430](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L430)
|
|
13138
13138
|
|
|
13139
13139
|
having 后置筛选器,用法类似 where
|
|
13140
13140
|
|
|
@@ -13154,7 +13154,7 @@ having 后置筛选器,用法类似 where
|
|
|
13154
13154
|
|
|
13155
13155
|
> **innerJoin**(`f`, `s?`, `suf?`, `pre?`): `this`
|
|
13156
13156
|
|
|
13157
|
-
Defined in: [lib/sql.ts:
|
|
13157
|
+
Defined in: [lib/sql.ts:401](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L401)
|
|
13158
13158
|
|
|
13159
13159
|
inner join 方法
|
|
13160
13160
|
|
|
@@ -13222,7 +13222,7 @@ Defined in: [lib/sql.ts:91](https://github.com/maiyunnet/kebab/blob/master/lib/s
|
|
|
13222
13222
|
|
|
13223
13223
|
> **join**(`f`, `s?`, `type?`, `suf?`, `pre?`): `this`
|
|
13224
13224
|
|
|
13225
|
-
Defined in: [lib/sql.ts:
|
|
13225
|
+
Defined in: [lib/sql.ts:353](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L353)
|
|
13226
13226
|
|
|
13227
13227
|
join 方法
|
|
13228
13228
|
|
|
@@ -13268,7 +13268,7 @@ ON 信息
|
|
|
13268
13268
|
|
|
13269
13269
|
> **leftJoin**(`f`, `s?`, `suf?`, `pre?`): `this`
|
|
13270
13270
|
|
|
13271
|
-
Defined in: [lib/sql.ts:
|
|
13271
|
+
Defined in: [lib/sql.ts:379](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L379)
|
|
13272
13272
|
|
|
13273
13273
|
left join 方法
|
|
13274
13274
|
|
|
@@ -13308,7 +13308,7 @@ ON 信息
|
|
|
13308
13308
|
|
|
13309
13309
|
> **limit**(`a`, `b?`): `this`
|
|
13310
13310
|
|
|
13311
|
-
Defined in: [lib/sql.ts:
|
|
13311
|
+
Defined in: [lib/sql.ts:712](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L712)
|
|
13312
13312
|
|
|
13313
13313
|
LIMIT(limit、offset, limit)
|
|
13314
13314
|
|
|
@@ -13336,7 +13336,7 @@ LIMIT(limit、offset, limit)
|
|
|
13336
13336
|
|
|
13337
13337
|
> **lock**(): `this`
|
|
13338
13338
|
|
|
13339
|
-
Defined in: [lib/sql.ts:
|
|
13339
|
+
Defined in: [lib/sql.ts:727](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L727)
|
|
13340
13340
|
|
|
13341
13341
|
追加消极锁,通常不建议使用
|
|
13342
13342
|
|
|
@@ -13350,7 +13350,7 @@ Defined in: [lib/sql.ts:720](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
13350
13350
|
|
|
13351
13351
|
> **rightJoin**(`f`, `s?`, `suf?`, `pre?`): `this`
|
|
13352
13352
|
|
|
13353
|
-
Defined in: [lib/sql.ts:
|
|
13353
|
+
Defined in: [lib/sql.ts:390](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L390)
|
|
13354
13354
|
|
|
13355
13355
|
right join 方法
|
|
13356
13356
|
|
|
@@ -13446,7 +13446,7 @@ sql 对象
|
|
|
13446
13446
|
|
|
13447
13447
|
> **unionAll**(`lsql`): `this`
|
|
13448
13448
|
|
|
13449
|
-
Defined in: [lib/sql.ts:
|
|
13449
|
+
Defined in: [lib/sql.ts:341](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L341)
|
|
13450
13450
|
|
|
13451
13451
|
所有联查另一个 sql 对象
|
|
13452
13452
|
|
|
@@ -13552,7 +13552,7 @@ Defined in: [lib/sql.ts:110](https://github.com/maiyunnet/kebab/blob/master/lib/
|
|
|
13552
13552
|
|
|
13553
13553
|
> **where**(`s`): `this`
|
|
13554
13554
|
|
|
13555
|
-
Defined in: [lib/sql.ts:
|
|
13555
|
+
Defined in: [lib/sql.ts:464](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L464)
|
|
13556
13556
|
|
|
13557
13557
|
筛选器
|
|
13558
13558
|
1. 'city': 'bj', 'type': '2'
|
|
@@ -13695,7 +13695,7 @@ lib/sql/functions/aoMix.md
|
|
|
13695
13695
|
|
|
13696
13696
|
> **aoMix**(`arr`): `Record`\<`string`, `string` \| `number` \| [`Json`](../../../index/type-aliases/Json.md)\>
|
|
13697
13697
|
|
|
13698
|
-
Defined in: [lib/sql.ts:
|
|
13698
|
+
Defined in: [lib/sql.ts:1210](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L1210)
|
|
13699
13699
|
|
|
13700
13700
|
将数组兑换为组合的对象(Array/Object mix)
|
|
13701
13701
|
|
|
@@ -13724,7 +13724,7 @@ lib/sql/functions/column.md
|
|
|
13724
13724
|
|
|
13725
13725
|
> **column**(`field`): `object`
|
|
13726
13726
|
|
|
13727
|
-
Defined in: [lib/sql.ts:
|
|
13727
|
+
Defined in: [lib/sql.ts:1231](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L1231)
|
|
13728
13728
|
|
|
13729
13729
|
创建字段对象
|
|
13730
13730
|
|
|
@@ -13763,7 +13763,7 @@ lib/sql/functions/format.md
|
|
|
13763
13763
|
|
|
13764
13764
|
> **format**(`sql`, `data`, `service?`): `string`
|
|
13765
13765
|
|
|
13766
|
-
Defined in: [lib/sql.ts:
|
|
13766
|
+
Defined in: [lib/sql.ts:1172](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L1172)
|
|
13767
13767
|
|
|
13768
13768
|
返回代入后的完整 SQL 字符串,这并不安全不能直接执行,只是用来调试打印 sql 语句
|
|
13769
13769
|
|
|
@@ -13804,7 +13804,7 @@ lib/sql/functions/get.md
|
|
|
13804
13804
|
|
|
13805
13805
|
> **get**(`opt`): [`Sql`](../classes/Sql.md)
|
|
13806
13806
|
|
|
13807
|
-
Defined in: [lib/sql.ts:
|
|
13807
|
+
Defined in: [lib/sql.ts:1145](https://github.com/maiyunnet/kebab/blob/master/lib/sql.ts#L1145)
|
|
13808
13808
|
|
|
13809
13809
|
创建 sql 对象
|
|
13810
13810
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '8.0.
|
|
9
|
+
export const VER = '8.0.4';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/sql.d.ts
CHANGED
|
@@ -222,7 +222,7 @@ export declare class Sql {
|
|
|
222
222
|
* @param pre 表前缀,仅请在 field 表名时倒入前缀
|
|
223
223
|
* @param suf 表后缀,仅请在 field 表名时倒入后缀,前面加 # 代表要强制 AS,可能是分表查询时用
|
|
224
224
|
*/
|
|
225
|
-
field(str: string | number |
|
|
225
|
+
field(str: string | number | [string, string[]], pre?: string, suf?: string): string;
|
|
226
226
|
/**
|
|
227
227
|
* --- 判断传入值是否是 field,还是别的对象 ---
|
|
228
228
|
* @param str
|
package/lib/sql.js
CHANGED
|
@@ -284,9 +284,16 @@ export class Sql {
|
|
|
284
284
|
* @param type 类型
|
|
285
285
|
*/
|
|
286
286
|
union(lsql, type = '') {
|
|
287
|
+
const offset = this._data.length;
|
|
287
288
|
this._data = this._data.concat(lsql.getData());
|
|
288
289
|
this._sql.push(' UNION ' + (type ? type + ' ' : ''));
|
|
289
|
-
|
|
290
|
+
let unionSql = lsql.getSql();
|
|
291
|
+
// --- PGSQL: 偏移 $N 占位符编号 ---
|
|
292
|
+
if (this._service === ESERVICE.PGSQL && offset > 0) {
|
|
293
|
+
unionSql = unionSql.replace(/\$(\d+)/g, (_, n) => `$${parseInt(n) + offset}`);
|
|
294
|
+
}
|
|
295
|
+
this._sql.push(unionSql);
|
|
296
|
+
this._placeholderCounter = this._data.length + 1;
|
|
290
297
|
return this;
|
|
291
298
|
}
|
|
292
299
|
/**
|
|
@@ -736,6 +743,13 @@ export class Sql {
|
|
|
736
743
|
}
|
|
737
744
|
sql[0] = sql[0].replace(/FROM [`\w, ]+/, 'FROM ' + table);
|
|
738
745
|
}
|
|
746
|
+
// --- PGSQL: 修改 where 后重新编号 $N 占位符 ---
|
|
747
|
+
if (this._service === ESERVICE.PGSQL && opt.where !== undefined) {
|
|
748
|
+
let counter = 1;
|
|
749
|
+
for (let i = 0; i < sql.length; ++i) {
|
|
750
|
+
sql[i] = sql[i].replace(/\$\d+/g, () => `$${counter++}`);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
739
753
|
return get({
|
|
740
754
|
'service': this._service,
|
|
741
755
|
'ctr': this._ctr,
|
|
@@ -799,6 +813,10 @@ export class Sql {
|
|
|
799
813
|
const q = this._service === ESERVICE.MYSQL ? '`' : '"';
|
|
800
814
|
if (Array.isArray(str)) {
|
|
801
815
|
this._data.push(...str[1]);
|
|
816
|
+
// --- PGSQL: 将 ? 占位符转换为 $N ---
|
|
817
|
+
if (this._service === ESERVICE.PGSQL) {
|
|
818
|
+
return this.field(str[0].replace(/\?/g, () => this._placeholder()));
|
|
819
|
+
}
|
|
802
820
|
return this.field(str[0]);
|
|
803
821
|
}
|
|
804
822
|
if (typeof str === 'number') {
|
package/package.json
CHANGED
package/sys/mod.js
CHANGED
|
@@ -134,7 +134,7 @@ export default class Mod {
|
|
|
134
134
|
sq.values(cs);
|
|
135
135
|
const r = await db.execute(sq.getSql(), sq.getData());
|
|
136
136
|
if (r.packet === null) {
|
|
137
|
-
lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
|
|
137
|
+
lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + '-' + sq.format()).replaceAll('"', '""'), '-error');
|
|
138
138
|
return false;
|
|
139
139
|
}
|
|
140
140
|
return r.packet.affected ? true : null;
|
|
@@ -154,7 +154,7 @@ export default class Mod {
|
|
|
154
154
|
sq.values(cs, vs.slice(i * line, (i + 1) * line));
|
|
155
155
|
const r = await db.execute(sq.getSql(), sq.getData());
|
|
156
156
|
if (r.packet === null) {
|
|
157
|
-
lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
|
|
157
|
+
lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + '-' + sq.format()).replaceAll('"', '""'), '-error');
|
|
158
158
|
return false;
|
|
159
159
|
}
|
|
160
160
|
if (r.packet.affected) {
|
|
@@ -204,7 +204,7 @@ export default class Mod {
|
|
|
204
204
|
}
|
|
205
205
|
const r = await db.execute(sq.getSql(), sq.getData());
|
|
206
206
|
if (r.packet === null) {
|
|
207
|
-
lCore.log(opt.ctr ?? {}, '[MOD][removeByWhere] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
207
|
+
lCore.log(opt.ctr ?? {}, '[MOD][removeByWhere] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + '-' + sq.format()).replaceAll('"', '""'), '-error');
|
|
208
208
|
return false;
|
|
209
209
|
}
|
|
210
210
|
if (r.packet.affected) {
|
|
@@ -259,7 +259,7 @@ export default class Mod {
|
|
|
259
259
|
}
|
|
260
260
|
const r = await db.execute(sq.getSql(), sq.getData());
|
|
261
261
|
if (r.packet === null) {
|
|
262
|
-
lCore.log(opt.ctr ?? {}, '[MOD][updateByWhere] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
262
|
+
lCore.log(opt.ctr ?? {}, '[MOD][updateByWhere] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + '-' + sq.format()).replaceAll('"', '""'), '-error');
|
|
263
263
|
return false;
|
|
264
264
|
}
|
|
265
265
|
if (r.packet.affected) {
|
|
@@ -358,7 +358,7 @@ export default class Mod {
|
|
|
358
358
|
.where({ [key]: keys });
|
|
359
359
|
const r = await db.execute(sq.getSql(), sq.getData());
|
|
360
360
|
if (r.packet === null) {
|
|
361
|
-
lCore.log(opt.ctr ?? {}, '[MOD][updateList] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
361
|
+
lCore.log(opt.ctr ?? {}, '[MOD][updateList] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + sq.format()).replaceAll('"', '""'), '-error');
|
|
362
362
|
return false;
|
|
363
363
|
}
|
|
364
364
|
}
|
|
@@ -502,7 +502,7 @@ export default class Mod {
|
|
|
502
502
|
sq.select(this._$primary, this._$table + (opt.index ? ('_' + opt.index) : '')).where(where);
|
|
503
503
|
const r = await db.query(sq.getSql(), sq.getData());
|
|
504
504
|
if (r.rows === null) {
|
|
505
|
-
lCore.log(opt.ctr ?? {}, '[
|
|
505
|
+
lCore.log(opt.ctr ?? {}, '[MOD][PRIMARYS] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + sq.format()).replaceAll('"', '""'), '-error');
|
|
506
506
|
return false;
|
|
507
507
|
}
|
|
508
508
|
const primarys = [];
|
|
@@ -615,7 +615,7 @@ export default class Mod {
|
|
|
615
615
|
}
|
|
616
616
|
// --- 未处理的错误 ---
|
|
617
617
|
const service = this._db.getService();
|
|
618
|
-
lCore.log(this._ctr ?? {}, '[MOD][create0][' + cstr._$table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
618
|
+
lCore.log(this._ctr ?? {}, '[MOD][create0][' + cstr._$table + '] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
619
619
|
if (lCore.globalConfig.debug) {
|
|
620
620
|
lCore.debug('[MOD][create0][' + cstr._$table + ']', service !== null ? lDb.ESERVICE[service] : 'NONE', r);
|
|
621
621
|
lCore.debug(this._sql.format());
|
|
@@ -629,7 +629,7 @@ export default class Mod {
|
|
|
629
629
|
r = await this._db.execute(this._sql.getSql(), this._sql.getData());
|
|
630
630
|
if (r.error) {
|
|
631
631
|
if (r.error.errno !== 1062) {
|
|
632
|
-
lCore.log(this._ctr ?? {}, '[MOD][create1][' + cstr._$table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
632
|
+
lCore.log(this._ctr ?? {}, '[MOD][create1][' + cstr._$table + '] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
633
633
|
if (lCore.globalConfig.debug) {
|
|
634
634
|
lCore.debug('[MOD][create1][' + cstr._$table + ']', r);
|
|
635
635
|
lCore.debug(this._sql.format());
|
|
@@ -692,7 +692,7 @@ export default class Mod {
|
|
|
692
692
|
}
|
|
693
693
|
const r = await this._db.query(this._sql.getSql(), this._sql.getData());
|
|
694
694
|
if (r.rows === null) {
|
|
695
|
-
lCore.log(this._ctr ?? {}, '[MOD][refresh] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
695
|
+
lCore.log(this._ctr ?? {}, '[MOD][refresh] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replace(/"/g, '""'), '-error');
|
|
696
696
|
return false;
|
|
697
697
|
}
|
|
698
698
|
if (r.rows.length === 0) {
|
|
@@ -723,7 +723,7 @@ export default class Mod {
|
|
|
723
723
|
});
|
|
724
724
|
const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
|
|
725
725
|
if (r.packet === null) {
|
|
726
|
-
lCore.log(this._ctr ?? {}, '[MOD][save] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
726
|
+
lCore.log(this._ctr ?? {}, '[MOD][save] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
727
727
|
return false;
|
|
728
728
|
}
|
|
729
729
|
if (r.packet.affected) {
|
|
@@ -744,7 +744,7 @@ export default class Mod {
|
|
|
744
744
|
}]);
|
|
745
745
|
const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
|
|
746
746
|
if (r.packet === null) {
|
|
747
|
-
lCore.log(this._ctr ?? {}, '[remove
|
|
747
|
+
lCore.log(this._ctr ?? {}, '[MOD][remove] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
748
748
|
return false;
|
|
749
749
|
}
|
|
750
750
|
if (r.packet.affected) {
|
|
@@ -766,7 +766,7 @@ export default class Mod {
|
|
|
766
766
|
}
|
|
767
767
|
const r = await this._db.query(this._sql.getSql(), this._sql.getData());
|
|
768
768
|
if (r.rows === null) {
|
|
769
|
-
lCore.log(this._ctr ?? {}, '[MOD][first] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + '-' + this._sql.format()).
|
|
769
|
+
lCore.log(this._ctr ?? {}, '[MOD][first] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
770
770
|
return false;
|
|
771
771
|
}
|
|
772
772
|
if (r.rows.length === 0) {
|
|
@@ -897,7 +897,7 @@ export default class Mod {
|
|
|
897
897
|
const lsql = sql.replace(/ LIMIT [0-9 ,]+(OFFSET [0-9]+)?/g, ` LIMIT ${remain} OFFSET ${cz}`);
|
|
898
898
|
const r = await this._db.query(lsql, this._sql.getData());
|
|
899
899
|
if (r.rows === null) {
|
|
900
|
-
lCore.log(this._ctr ?? {}, '[MOD][all] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
900
|
+
lCore.log(this._ctr ?? {}, '[MOD][all] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
901
901
|
return false;
|
|
902
902
|
}
|
|
903
903
|
if (key) {
|
|
@@ -934,7 +934,7 @@ export default class Mod {
|
|
|
934
934
|
const contain = this._contain ? lCore.clone(this._contain.list) : null;
|
|
935
935
|
const r = await this._db.query(this._sql.getSql(), this._sql.getData());
|
|
936
936
|
if (r.rows === null) {
|
|
937
|
-
lCore.log(this._ctr ?? {}, '[MOD][all] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
937
|
+
lCore.log(this._ctr ?? {}, '[MOD][all] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
938
938
|
return false;
|
|
939
939
|
}
|
|
940
940
|
// --- 检查没被查到的必包含项 ---
|
|
@@ -1059,7 +1059,7 @@ export default class Mod {
|
|
|
1059
1059
|
const lsql = sql.replace(/ LIMIT [0-9 ,]+(OFFSET [0-9]+)?/g, ` LIMIT ${remain} OFFSET ${cz}`);
|
|
1060
1060
|
const r = await this._db.query(lsql, this._sql.getData());
|
|
1061
1061
|
if (r.rows === null) {
|
|
1062
|
-
lCore.log(this._ctr ?? {}, '[MOD][allArray] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
1062
|
+
lCore.log(this._ctr ?? {}, '[MOD][allArray] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
1063
1063
|
return false;
|
|
1064
1064
|
}
|
|
1065
1065
|
if (key) {
|
|
@@ -1081,7 +1081,7 @@ export default class Mod {
|
|
|
1081
1081
|
const contain = this._contain ? lCore.clone(this._contain.list) : null;
|
|
1082
1082
|
const r = await this._db.query(this._sql.getSql(), this._sql.getData());
|
|
1083
1083
|
if (r.rows === null) {
|
|
1084
|
-
lCore.log(this._ctr ?? {}, '[MOD][allArray] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
1084
|
+
lCore.log(this._ctr ?? {}, '[MOD][allArray] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
1085
1085
|
return false;
|
|
1086
1086
|
}
|
|
1087
1087
|
// --- 检查没被查到的必包含项 ---
|
|
@@ -1130,7 +1130,7 @@ export default class Mod {
|
|
|
1130
1130
|
async explain(all = false) {
|
|
1131
1131
|
const r = await this._db.query('EXPLAIN ' + this._sql.getSql(), this._sql.getData());
|
|
1132
1132
|
if (r.rows === null) {
|
|
1133
|
-
lCore.log(this._ctr ?? {}, '[MOD][explain] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
1133
|
+
lCore.log(this._ctr ?? {}, '[MOD][explain] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
1134
1134
|
return false;
|
|
1135
1135
|
}
|
|
1136
1136
|
if (!r.rows[0]) {
|
|
@@ -1173,7 +1173,7 @@ export default class Mod {
|
|
|
1173
1173
|
const sql = this._formatTotal(this._sql.getSql(), f);
|
|
1174
1174
|
const r = await this._db.query(sql, this._sql.getData());
|
|
1175
1175
|
if (r.rows === null) {
|
|
1176
|
-
lCore.log(this._ctr ?? {}, '[MOD][total] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
1176
|
+
lCore.log(this._ctr ?? {}, '[MOD][total] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
1177
1177
|
return 0;
|
|
1178
1178
|
}
|
|
1179
1179
|
let count = 0;
|
|
@@ -1191,7 +1191,7 @@ export default class Mod {
|
|
|
1191
1191
|
'SELECT COUNT(0) AS "count" FROM');
|
|
1192
1192
|
const r = await this._db.query(sql, this._sql.getData());
|
|
1193
1193
|
if (r.rows === null) {
|
|
1194
|
-
lCore.log(this._ctr ?? {}, '[MOD][count] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).
|
|
1194
|
+
lCore.log(this._ctr ?? {}, '[MOD][count] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
|
|
1195
1195
|
return 0;
|
|
1196
1196
|
}
|
|
1197
1197
|
let count = 0;
|
package/sys/monitor/watchdog.js
CHANGED
|
@@ -84,6 +84,12 @@ function captureDiag(blockSec) {
|
|
|
84
84
|
const pauseTimeout = setTimeout(() => {
|
|
85
85
|
if (!didPause) {
|
|
86
86
|
timedOut = true;
|
|
87
|
+
try {
|
|
88
|
+
session.post('Debugger.resume');
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// --- 忽略 ---
|
|
92
|
+
}
|
|
87
93
|
try {
|
|
88
94
|
session.post('Debugger.disable');
|
|
89
95
|
}
|
|
@@ -171,10 +177,6 @@ function captureDiag(blockSec) {
|
|
|
171
177
|
}
|
|
172
178
|
return;
|
|
173
179
|
}
|
|
174
|
-
if (timedOut) {
|
|
175
|
-
clearTimeout(pauseTimeout);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
180
|
try {
|
|
179
181
|
session.post('Debugger.pause', (err2) => {
|
|
180
182
|
if (err2 || timedOut) {
|
|
@@ -249,6 +251,10 @@ setInterval(() => {
|
|
|
249
251
|
if (lastHb <= 0 || now - lastHb < data.threshold) {
|
|
250
252
|
return;
|
|
251
253
|
}
|
|
254
|
+
// --- 调试模式下跳过阻塞检测,避免干扰 IDE 调试器 ---
|
|
255
|
+
if (Atomics.load(view, 1) === 1) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
252
258
|
if (now - lastAlertTime < data.cooldown) {
|
|
253
259
|
return;
|
|
254
260
|
}
|
package/sys/monitor.js
CHANGED
|
@@ -49,6 +49,12 @@ let requestCounter = 0;
|
|
|
49
49
|
let lastDiagnosticTime = 0;
|
|
50
50
|
/** --- 是否正在进行 CPU Profile 采集 --- */
|
|
51
51
|
let profiling = false;
|
|
52
|
+
/**
|
|
53
|
+
* --- 检测当前是否处于调试模式(以 --inspect 启动或 IDE 调试器已连接) ---
|
|
54
|
+
*/
|
|
55
|
+
function isDebugMode() {
|
|
56
|
+
return !!inspector.url();
|
|
57
|
+
}
|
|
52
58
|
// --- 看门狗相关 ---
|
|
53
59
|
/** --- 看门狗 Worker 实例 --- */
|
|
54
60
|
let watchdog = null;
|
|
@@ -85,10 +91,11 @@ export function start(opt) {
|
|
|
85
91
|
lastOsCpus = os.cpus();
|
|
86
92
|
spikeCounter = 0;
|
|
87
93
|
lastDiagnosticTime = 0;
|
|
88
|
-
// ---
|
|
89
|
-
heartbeatBuffer = new SharedArrayBuffer(
|
|
94
|
+
// --- 初始化心跳共享内存(索引 0: 秒级时间戳, 索引 1: 调试模式标志) ---
|
|
95
|
+
heartbeatBuffer = new SharedArrayBuffer(8);
|
|
90
96
|
heartbeatView = new Int32Array(heartbeatBuffer);
|
|
91
97
|
Atomics.store(heartbeatView, 0, Math.floor(Date.now() / 1000));
|
|
98
|
+
Atomics.store(heartbeatView, 1, isDebugMode() ? 1 : 0);
|
|
92
99
|
// --- 启用事件循环延迟直方图 ---
|
|
93
100
|
eloopHistogram = perfHooks.monitorEventLoopDelay({ 'resolution': 20 });
|
|
94
101
|
eloopHistogram.enable();
|
|
@@ -259,6 +266,8 @@ function check() {
|
|
|
259
266
|
// --- 更新心跳时间戳,让看门狗线程知道主线程还活着 ---
|
|
260
267
|
if (heartbeatView) {
|
|
261
268
|
Atomics.store(heartbeatView, 0, Math.floor(now / 1000));
|
|
269
|
+
// --- 更新调试模式标志,让看门狗线程知道当前是否在调试 ---
|
|
270
|
+
Atomics.store(heartbeatView, 1, isDebugMode() ? 1 : 0);
|
|
262
271
|
}
|
|
263
272
|
/** --- 计算本周期进程 CPU 使用率(单核基准) --- */
|
|
264
273
|
let cpuPercent = 0;
|
|
@@ -284,6 +293,11 @@ function check() {
|
|
|
284
293
|
}
|
|
285
294
|
// --- 检测事件循环阻塞:实际间隔远大于预期说明事件循环曾被阻塞 ---
|
|
286
295
|
if (actualElapsed > INTERVAL * 3) {
|
|
296
|
+
// --- 调试模式下断点暂停会导致计时差异,跳过阻塞检测 ---
|
|
297
|
+
if (isDebugMode()) {
|
|
298
|
+
spikeCounter = 0;
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
287
301
|
const blockMs = actualElapsed - INTERVAL;
|
|
288
302
|
const alerts = [
|
|
289
303
|
`ELOOP_BLOCKED ${Math.round(blockMs)}ms`
|