w-orm-postgresql 1.0.10 → 1.0.11

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.
@@ -514,7 +514,7 @@
514
514
 
515
515
  <dt class="tag-source">Source:</dt>
516
516
  <dd class="tag-source"><ul class="dummy"><li>
517
- <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line227">line 227</a>
517
+ <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line259">line 259</a>
518
518
  </li></ul></dd>
519
519
 
520
520
 
@@ -771,7 +771,7 @@
771
771
 
772
772
  <dt class="tag-source">Source:</dt>
773
773
  <dd class="tag-source"><ul class="dummy"><li>
774
- <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line1021">line 1021</a>
774
+ <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line1094">line 1094</a>
775
775
  </li></ul></dd>
776
776
 
777
777
 
@@ -934,7 +934,7 @@
934
934
 
935
935
  <dt class="tag-source">Source:</dt>
936
936
  <dd class="tag-source"><ul class="dummy"><li>
937
- <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line1171">line 1171</a>
937
+ <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line1255">line 1255</a>
938
938
  </li></ul></dd>
939
939
 
940
940
 
@@ -1115,7 +1115,7 @@
1115
1115
 
1116
1116
  <dt class="tag-source">Source:</dt>
1117
1117
  <dd class="tag-source"><ul class="dummy"><li>
1118
- <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line538">line 538</a>
1118
+ <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line595">line 595</a>
1119
1119
  </li></ul></dd>
1120
1120
 
1121
1121
 
@@ -1283,7 +1283,7 @@ nInserted與nModified恆同時出現,無對應行為時填0。
1283
1283
 
1284
1284
  <dt class="tag-source">Source:</dt>
1285
1285
  <dd class="tag-source"><ul class="dummy"><li>
1286
- <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line675">line 675</a>
1286
+ <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line735">line 735</a>
1287
1287
  </li></ul></dd>
1288
1288
 
1289
1289
 
@@ -1570,7 +1570,7 @@ nInserted與nModified恆同時出現,無對應行為時填0。
1570
1570
 
1571
1571
  <dt class="tag-source">Source:</dt>
1572
1572
  <dd class="tag-source"><ul class="dummy"><li>
1573
- <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line319">line 319</a>
1573
+ <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line359">line 359</a>
1574
1574
  </li></ul></dd>
1575
1575
 
1576
1576
 
@@ -1791,7 +1791,7 @@ nInserted與nModified恆同時出現,無對應行為時填0。
1791
1791
 
1792
1792
  <dt class="tag-source">Source:</dt>
1793
1793
  <dd class="tag-source"><ul class="dummy"><li>
1794
- <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line414">line 414</a>
1794
+ <a href="WOrmPostgresql.mjs.html">WOrmPostgresql.mjs</a>, <a href="WOrmPostgresql.mjs.html#line462">line 462</a>
1795
1795
  </li></ul></dd>
1796
1796
 
1797
1797
 
@@ -1954,7 +1954,7 @@ nInserted與nModified恆同時出現,無對應行為時填0。
1954
1954
  <br class="clear">
1955
1955
 
1956
1956
  <footer>
1957
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Aug 16 2026 23:54:17 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1957
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Mon Aug 17 2026 09:06:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1958
1958
  </footer>
1959
1959
 
1960
1960
  <script>prettyPrint();</script>
@@ -45,8 +45,7 @@
45
45
 
46
46
  <section>
47
47
  <article>
48
- <pre class="prettyprint source linenums"><code>import events from 'events'
49
- import pg from 'pg'
48
+ <pre class="prettyprint source linenums"><code>import pg from 'pg'
50
49
  import mongoSql from 'mongo-sql'
51
50
  import size from 'lodash-es/size.js'
52
51
  import get from 'lodash-es/get.js'
@@ -67,6 +66,7 @@ import isint from 'wsemi/src/isint.mjs'
67
66
  import isbol from 'wsemi/src/isbol.mjs'
68
67
  import isDate from 'wsemi/src/isDate.mjs'
69
68
  import haskey from 'wsemi/src/haskey.mjs'
69
+ import evem from 'wsemi/src/evem.mjs'
70
70
  import pmSeries from 'wsemi/src/pmSeries.mjs'
71
71
 
72
72
 
@@ -220,8 +220,40 @@ function WOrmPostgresql(opt = {}) {
220
220
  let connectionString = `${url}/${db}`
221
221
  // console.log('connectionString', connectionString)
222
222
 
223
- //ee
224
- let ee = new events.EventEmitter()
223
+ //ee, 採eventemitter3而不採Node內建之events.EventEmitter,
224
+ //因後者於'error'無監聽者時會將錯誤直接拋出, 將使操作行為隨呼叫端是否註冊監聽而異
225
+ let ee = evem()
226
+
227
+ //getErrMsg, 取錯誤訊息字串, 供逐筆結果之err欄位與error事件使用
228
+ let getErrMsg = (err) => {
229
+ let m = get(err, 'message')
230
+ if (isestr(m)) {
231
+ return m
232
+ }
233
+ return String(err)
234
+ }
235
+
236
+ //emitChange, 資料實際異動成功後發出, 事件僅為附加通知不承擔回傳義務
237
+ //訂閱函數拋錯不得影響本次操作, 故一律以try/catch包覆, 收斂於此以免逐處遺漏
238
+ let emitChange = (mode, data, res) => {
239
+ try {
240
+ ee.emit('change', mode, data, res)
241
+ }
242
+ catch (errEmit) {
243
+ console.log(errEmit)
244
+ }
245
+ }
246
+
247
+ //emitError, 操作發生錯誤時發出, 錯誤訊息一律轉為字串
248
+ //正常結果(如查無數據、主鍵未命中、內容相同而未寫入)不得發出, 以免監聽者將常態當異常
249
+ let emitError = (mode, data, err) => {
250
+ try {
251
+ ee.emit('error', mode, data, getErrMsg(err))
252
+ }
253
+ catch (errEmit) {
254
+ console.log(errEmit)
255
+ }
256
+ }
225
257
 
226
258
  //PgClient
227
259
  let PgClient = pg.Client
@@ -299,6 +331,10 @@ function WOrmPostgresql(opt = {}) {
299
331
 
300
332
  //check
301
333
  if (isErr) {
334
+
335
+ //emit, 整批性錯誤於reject之前發出
336
+ emitError('createTable', arr, res)
337
+
302
338
  return Promise.reject(res)
303
339
  }
304
340
 
@@ -349,6 +385,10 @@ function WOrmPostgresql(opt = {}) {
349
385
 
350
386
  //check
351
387
  if (isErr) {
388
+
389
+ //emit, 整批性錯誤於reject之前發出
390
+ emitError('createTable', arr, res)
391
+
352
392
  return Promise.reject(res)
353
393
  }
354
394
 
@@ -393,6 +433,10 @@ function WOrmPostgresql(opt = {}) {
393
433
 
394
434
  //check
395
435
  if (isErr) {
436
+
437
+ //emit, 整批性錯誤於reject之前發出, 讀取函數無輸入數據故data為null
438
+ emitError('select', null, res)
439
+
396
440
  return Promise.reject(res)
397
441
  }
398
442
 
@@ -441,6 +485,10 @@ function WOrmPostgresql(opt = {}) {
441
485
 
442
486
  //check
443
487
  if (isErr) {
488
+
489
+ //emit, 整批性錯誤於reject之前發出, 讀取函數無輸入數據故data為null
490
+ emitError('select', null, res)
491
+
444
492
  return Promise.reject(res)
445
493
  }
446
494
 
@@ -499,6 +547,10 @@ function WOrmPostgresql(opt = {}) {
499
547
 
500
548
  //check
501
549
  if (isErr) {
550
+
551
+ //emit, 整批性錯誤於reject之前發出, 讀取函數無輸入數據故data為null
552
+ emitError('selectByPk', null, res)
553
+
502
554
  return Promise.reject(res)
503
555
  }
504
556
 
@@ -565,6 +617,11 @@ function WOrmPostgresql(opt = {}) {
565
617
 
566
618
  //check
567
619
  if (isErr) {
620
+
621
+ //emit, 整批性錯誤於reject之前發出, 讀取函數無輸入數據故data為null
622
+ //主鍵未命中與主鍵值無效皆為正常結果而不設isErr, 故不會誤發error
623
+ emitError('selectByPk', null, res)
624
+
568
625
  return Promise.reject(res)
569
626
  }
570
627
 
@@ -616,6 +673,10 @@ function WOrmPostgresql(opt = {}) {
616
673
 
617
674
  //check
618
675
  if (isErr) {
676
+
677
+ //emit, 整批性錯誤於reject之前發出
678
+ emitError('insert', data, res)
679
+
619
680
  return Promise.reject(res)
620
681
  }
621
682
 
@@ -686,16 +747,15 @@ function WOrmPostgresql(opt = {}) {
686
747
 
687
748
  //emit
688
749
  if (!isErr) {
689
- try {
690
- ee.emit('change', 'insert', data, res)
691
- }
692
- catch (err) {
693
- console.log(err)
694
- }
750
+ emitChange('insert', data, res)
695
751
  }
696
752
 
697
753
  //check
698
754
  if (isErr) {
755
+
756
+ //emit, 整批性錯誤於reject之前發出
757
+ emitError('insert', data, res)
758
+
699
759
  return Promise.reject(res)
700
760
  }
701
761
 
@@ -752,6 +812,10 @@ function WOrmPostgresql(opt = {}) {
752
812
 
753
813
  //check
754
814
  if (isErr) {
815
+
816
+ //emit, 整批性錯誤於reject之前發出
817
+ emitError('save', data, res)
818
+
755
819
  return Promise.reject(res)
756
820
  }
757
821
 
@@ -1017,6 +1081,16 @@ function WOrmPostgresql(opt = {}) {
1017
1081
 
1018
1082
  }
1019
1083
 
1084
+ //emit, 該筆經插入而產生者另發mode為insert之change事件, 供呼叫端區辨新增與更新
1085
+ if (rest.nInserted === 1) {
1086
+ emitChange('insert', [v], rest)
1087
+ }
1088
+
1089
+ //emit, 逐筆失敗於該筆結果定案後發出, 每筆一次
1090
+ if (rest.ok === 0) {
1091
+ emitError('save', [v], rest.err)
1092
+ }
1093
+
1020
1094
  return rest
1021
1095
  })
1022
1096
 
@@ -1037,16 +1111,15 @@ function WOrmPostgresql(opt = {}) {
1037
1111
 
1038
1112
  //emit
1039
1113
  if (!isErr) {
1040
- try {
1041
- ee.emit('change', 'save', data, res)
1042
- }
1043
- catch (err) {
1044
- console.log(err)
1045
- }
1114
+ emitChange('save', data, res)
1046
1115
  }
1047
1116
 
1048
1117
  //check
1049
1118
  if (isErr) {
1119
+
1120
+ //emit, 整批性錯誤於reject之前發出
1121
+ emitError('save', data, res)
1122
+
1050
1123
  return Promise.reject(res)
1051
1124
  }
1052
1125
 
@@ -1095,6 +1168,10 @@ function WOrmPostgresql(opt = {}) {
1095
1168
 
1096
1169
  //check
1097
1170
  if (isErr) {
1171
+
1172
+ //emit, 整批性錯誤於reject之前發出
1173
+ emitError('del', data, res)
1174
+
1098
1175
  return Promise.reject(res)
1099
1176
  }
1100
1177
 
@@ -1130,6 +1207,9 @@ function WOrmPostgresql(opt = {}) {
1130
1207
  err: `invalid ${pkName}[${pkv}]`,
1131
1208
  }
1132
1209
 
1210
+ //emit, 逐筆失敗於該筆結果定案後發出, 每筆一次
1211
+ emitError('del', [v], rest.err)
1212
+
1133
1213
  return rest
1134
1214
  }
1135
1215
 
@@ -1169,6 +1249,11 @@ function WOrmPostgresql(opt = {}) {
1169
1249
 
1170
1250
  })
1171
1251
 
1252
+ //emit, 逐筆失敗於該筆結果定案後發出, 每筆一次
1253
+ if (rest.ok === 0) {
1254
+ emitError('del', [v], rest.err)
1255
+ }
1256
+
1172
1257
  return rest
1173
1258
  })
1174
1259
 
@@ -1189,16 +1274,15 @@ function WOrmPostgresql(opt = {}) {
1189
1274
 
1190
1275
  //emit
1191
1276
  if (!isErr) {
1192
- try {
1193
- ee.emit('change', 'del', data, res)
1194
- }
1195
- catch (err) {
1196
- console.log(err)
1197
- }
1277
+ emitChange('del', data, res)
1198
1278
  }
1199
1279
 
1200
1280
  //check
1201
1281
  if (isErr) {
1282
+
1283
+ //emit, 整批性錯誤於reject之前發出
1284
+ emitError('del', data, res)
1285
+
1202
1286
  return Promise.reject(res)
1203
1287
  }
1204
1288
 
@@ -1237,6 +1321,10 @@ function WOrmPostgresql(opt = {}) {
1237
1321
 
1238
1322
  //check
1239
1323
  if (isErr) {
1324
+
1325
+ //emit, 整批性錯誤於reject之前發出, 無輸入數據故data為null
1326
+ emitError('delAll', null, res)
1327
+
1240
1328
  return Promise.reject(res)
1241
1329
  }
1242
1330
 
@@ -1300,16 +1388,15 @@ function WOrmPostgresql(opt = {}) {
1300
1388
 
1301
1389
  //emit
1302
1390
  if (!isErr) {
1303
- try {
1304
- ee.emit('change', 'delAll', null, res)
1305
- }
1306
- catch (err) {
1307
- console.log(err)
1308
- }
1391
+ emitChange('delAll', null, res)
1309
1392
  }
1310
1393
 
1311
1394
  //check
1312
1395
  if (isErr) {
1396
+
1397
+ //emit, 整批性錯誤於reject之前發出
1398
+ emitError('delAll', null, res)
1399
+
1313
1400
  return Promise.reject(res)
1314
1401
  }
1315
1402
 
@@ -1344,7 +1431,7 @@ export default WOrmPostgresql
1344
1431
  <br class="clear">
1345
1432
 
1346
1433
  <footer>
1347
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Aug 16 2026 23:54:17 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1434
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Mon Aug 17 2026 09:06:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1348
1435
  </footer>
1349
1436
 
1350
1437
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -71,7 +71,7 @@
71
71
  <br class="clear">
72
72
 
73
73
  <footer>
74
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Aug 16 2026 23:54:17 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
74
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Mon Aug 17 2026 09:06:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
75
75
  </footer>
76
76
 
77
77
  <script>prettyPrint();</script>
package/g-basic.mjs CHANGED
@@ -369,6 +369,7 @@ test()
369
369
  // value: 447
370
370
  // }
371
371
  // ]
372
+ // change insert
372
373
  // change save
373
374
  // save then [ { n: 1, nInserted: 1, nModified: 0, ok: 1 } ]
374
375
  // change del
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w-orm-postgresql",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "main": "dist/w-orm-postgresql.umd.js",
5
5
  "dependencies": {
6
6
  "mongo-sql": "^6.2.0",
@@ -1,4 +1,3 @@
1
- import events from 'events'
2
1
  import pg from 'pg'
3
2
  import mongoSql from 'mongo-sql'
4
3
  import size from 'lodash-es/size.js'
@@ -20,6 +19,7 @@ import isint from 'wsemi/src/isint.mjs'
20
19
  import isbol from 'wsemi/src/isbol.mjs'
21
20
  import isDate from 'wsemi/src/isDate.mjs'
22
21
  import haskey from 'wsemi/src/haskey.mjs'
22
+ import evem from 'wsemi/src/evem.mjs'
23
23
  import pmSeries from 'wsemi/src/pmSeries.mjs'
24
24
 
25
25
 
@@ -173,8 +173,40 @@ function WOrmPostgresql(opt = {}) {
173
173
  let connectionString = `${url}/${db}`
174
174
  // console.log('connectionString', connectionString)
175
175
 
176
- //ee
177
- let ee = new events.EventEmitter()
176
+ //ee, 採eventemitter3而不採Node內建之events.EventEmitter,
177
+ //因後者於'error'無監聽者時會將錯誤直接拋出, 將使操作行為隨呼叫端是否註冊監聽而異
178
+ let ee = evem()
179
+
180
+ //getErrMsg, 取錯誤訊息字串, 供逐筆結果之err欄位與error事件使用
181
+ let getErrMsg = (err) => {
182
+ let m = get(err, 'message')
183
+ if (isestr(m)) {
184
+ return m
185
+ }
186
+ return String(err)
187
+ }
188
+
189
+ //emitChange, 資料實際異動成功後發出, 事件僅為附加通知不承擔回傳義務
190
+ //訂閱函數拋錯不得影響本次操作, 故一律以try/catch包覆, 收斂於此以免逐處遺漏
191
+ let emitChange = (mode, data, res) => {
192
+ try {
193
+ ee.emit('change', mode, data, res)
194
+ }
195
+ catch (errEmit) {
196
+ console.log(errEmit)
197
+ }
198
+ }
199
+
200
+ //emitError, 操作發生錯誤時發出, 錯誤訊息一律轉為字串
201
+ //正常結果(如查無數據、主鍵未命中、內容相同而未寫入)不得發出, 以免監聽者將常態當異常
202
+ let emitError = (mode, data, err) => {
203
+ try {
204
+ ee.emit('error', mode, data, getErrMsg(err))
205
+ }
206
+ catch (errEmit) {
207
+ console.log(errEmit)
208
+ }
209
+ }
178
210
 
179
211
  //PgClient
180
212
  let PgClient = pg.Client
@@ -252,6 +284,10 @@ function WOrmPostgresql(opt = {}) {
252
284
 
253
285
  //check
254
286
  if (isErr) {
287
+
288
+ //emit, 整批性錯誤於reject之前發出
289
+ emitError('createTable', arr, res)
290
+
255
291
  return Promise.reject(res)
256
292
  }
257
293
 
@@ -302,6 +338,10 @@ function WOrmPostgresql(opt = {}) {
302
338
 
303
339
  //check
304
340
  if (isErr) {
341
+
342
+ //emit, 整批性錯誤於reject之前發出
343
+ emitError('createTable', arr, res)
344
+
305
345
  return Promise.reject(res)
306
346
  }
307
347
 
@@ -346,6 +386,10 @@ function WOrmPostgresql(opt = {}) {
346
386
 
347
387
  //check
348
388
  if (isErr) {
389
+
390
+ //emit, 整批性錯誤於reject之前發出, 讀取函數無輸入數據故data為null
391
+ emitError('select', null, res)
392
+
349
393
  return Promise.reject(res)
350
394
  }
351
395
 
@@ -394,6 +438,10 @@ function WOrmPostgresql(opt = {}) {
394
438
 
395
439
  //check
396
440
  if (isErr) {
441
+
442
+ //emit, 整批性錯誤於reject之前發出, 讀取函數無輸入數據故data為null
443
+ emitError('select', null, res)
444
+
397
445
  return Promise.reject(res)
398
446
  }
399
447
 
@@ -452,6 +500,10 @@ function WOrmPostgresql(opt = {}) {
452
500
 
453
501
  //check
454
502
  if (isErr) {
503
+
504
+ //emit, 整批性錯誤於reject之前發出, 讀取函數無輸入數據故data為null
505
+ emitError('selectByPk', null, res)
506
+
455
507
  return Promise.reject(res)
456
508
  }
457
509
 
@@ -518,6 +570,11 @@ function WOrmPostgresql(opt = {}) {
518
570
 
519
571
  //check
520
572
  if (isErr) {
573
+
574
+ //emit, 整批性錯誤於reject之前發出, 讀取函數無輸入數據故data為null
575
+ //主鍵未命中與主鍵值無效皆為正常結果而不設isErr, 故不會誤發error
576
+ emitError('selectByPk', null, res)
577
+
521
578
  return Promise.reject(res)
522
579
  }
523
580
 
@@ -569,6 +626,10 @@ function WOrmPostgresql(opt = {}) {
569
626
 
570
627
  //check
571
628
  if (isErr) {
629
+
630
+ //emit, 整批性錯誤於reject之前發出
631
+ emitError('insert', data, res)
632
+
572
633
  return Promise.reject(res)
573
634
  }
574
635
 
@@ -639,16 +700,15 @@ function WOrmPostgresql(opt = {}) {
639
700
 
640
701
  //emit
641
702
  if (!isErr) {
642
- try {
643
- ee.emit('change', 'insert', data, res)
644
- }
645
- catch (err) {
646
- console.log(err)
647
- }
703
+ emitChange('insert', data, res)
648
704
  }
649
705
 
650
706
  //check
651
707
  if (isErr) {
708
+
709
+ //emit, 整批性錯誤於reject之前發出
710
+ emitError('insert', data, res)
711
+
652
712
  return Promise.reject(res)
653
713
  }
654
714
 
@@ -705,6 +765,10 @@ function WOrmPostgresql(opt = {}) {
705
765
 
706
766
  //check
707
767
  if (isErr) {
768
+
769
+ //emit, 整批性錯誤於reject之前發出
770
+ emitError('save', data, res)
771
+
708
772
  return Promise.reject(res)
709
773
  }
710
774
 
@@ -970,6 +1034,16 @@ function WOrmPostgresql(opt = {}) {
970
1034
 
971
1035
  }
972
1036
 
1037
+ //emit, 該筆經插入而產生者另發mode為insert之change事件, 供呼叫端區辨新增與更新
1038
+ if (rest.nInserted === 1) {
1039
+ emitChange('insert', [v], rest)
1040
+ }
1041
+
1042
+ //emit, 逐筆失敗於該筆結果定案後發出, 每筆一次
1043
+ if (rest.ok === 0) {
1044
+ emitError('save', [v], rest.err)
1045
+ }
1046
+
973
1047
  return rest
974
1048
  })
975
1049
 
@@ -990,16 +1064,15 @@ function WOrmPostgresql(opt = {}) {
990
1064
 
991
1065
  //emit
992
1066
  if (!isErr) {
993
- try {
994
- ee.emit('change', 'save', data, res)
995
- }
996
- catch (err) {
997
- console.log(err)
998
- }
1067
+ emitChange('save', data, res)
999
1068
  }
1000
1069
 
1001
1070
  //check
1002
1071
  if (isErr) {
1072
+
1073
+ //emit, 整批性錯誤於reject之前發出
1074
+ emitError('save', data, res)
1075
+
1003
1076
  return Promise.reject(res)
1004
1077
  }
1005
1078
 
@@ -1048,6 +1121,10 @@ function WOrmPostgresql(opt = {}) {
1048
1121
 
1049
1122
  //check
1050
1123
  if (isErr) {
1124
+
1125
+ //emit, 整批性錯誤於reject之前發出
1126
+ emitError('del', data, res)
1127
+
1051
1128
  return Promise.reject(res)
1052
1129
  }
1053
1130
 
@@ -1083,6 +1160,9 @@ function WOrmPostgresql(opt = {}) {
1083
1160
  err: `invalid ${pkName}[${pkv}]`,
1084
1161
  }
1085
1162
 
1163
+ //emit, 逐筆失敗於該筆結果定案後發出, 每筆一次
1164
+ emitError('del', [v], rest.err)
1165
+
1086
1166
  return rest
1087
1167
  }
1088
1168
 
@@ -1122,6 +1202,11 @@ function WOrmPostgresql(opt = {}) {
1122
1202
 
1123
1203
  })
1124
1204
 
1205
+ //emit, 逐筆失敗於該筆結果定案後發出, 每筆一次
1206
+ if (rest.ok === 0) {
1207
+ emitError('del', [v], rest.err)
1208
+ }
1209
+
1125
1210
  return rest
1126
1211
  })
1127
1212
 
@@ -1142,16 +1227,15 @@ function WOrmPostgresql(opt = {}) {
1142
1227
 
1143
1228
  //emit
1144
1229
  if (!isErr) {
1145
- try {
1146
- ee.emit('change', 'del', data, res)
1147
- }
1148
- catch (err) {
1149
- console.log(err)
1150
- }
1230
+ emitChange('del', data, res)
1151
1231
  }
1152
1232
 
1153
1233
  //check
1154
1234
  if (isErr) {
1235
+
1236
+ //emit, 整批性錯誤於reject之前發出
1237
+ emitError('del', data, res)
1238
+
1155
1239
  return Promise.reject(res)
1156
1240
  }
1157
1241
 
@@ -1190,6 +1274,10 @@ function WOrmPostgresql(opt = {}) {
1190
1274
 
1191
1275
  //check
1192
1276
  if (isErr) {
1277
+
1278
+ //emit, 整批性錯誤於reject之前發出, 無輸入數據故data為null
1279
+ emitError('delAll', null, res)
1280
+
1193
1281
  return Promise.reject(res)
1194
1282
  }
1195
1283
 
@@ -1253,16 +1341,15 @@ function WOrmPostgresql(opt = {}) {
1253
1341
 
1254
1342
  //emit
1255
1343
  if (!isErr) {
1256
- try {
1257
- ee.emit('change', 'delAll', null, res)
1258
- }
1259
- catch (err) {
1260
- console.log(err)
1261
- }
1344
+ emitChange('delAll', null, res)
1262
1345
  }
1263
1346
 
1264
1347
  //check
1265
1348
  if (isErr) {
1349
+
1350
+ //emit, 整批性錯誤於reject之前發出
1351
+ emitError('delAll', null, res)
1352
+
1266
1353
  return Promise.reject(res)
1267
1354
  }
1268
1355