w-orm-mongodb 1.1.38 → 1.1.39

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.
@@ -29,7 +29,7 @@
29
29
  <nav >
30
30
 
31
31
 
32
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WOrmMongodb.html">WOrmMongodb</a><ul class='methods'><li data-type='method'><a href="WOrmMongodb.html#.del">del</a></li><li data-type='method'><a href="WOrmMongodb.html#.delAll">delAll</a></li><li data-type='method'><a href="WOrmMongodb.html#.delAllGfs">delAllGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.delGfs">delGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.insert">insert</a></li><li data-type='method'><a href="WOrmMongodb.html#.insertGfs">insertGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.save">save</a></li><li data-type='method'><a href="WOrmMongodb.html#.select">select</a></li><li data-type='method'><a href="WOrmMongodb.html#.selectById">selectById</a></li><li data-type='method'><a href="WOrmMongodb.html#.selectByIdGfs">selectByIdGfs</a></li></ul></li></ul>
32
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WOrmMongodb.html">WOrmMongodb</a><ul class='methods'><li data-type='method'><a href="WOrmMongodb.html#.del">del</a></li><li data-type='method'><a href="WOrmMongodb.html#.delAll">delAll</a></li><li data-type='method'><a href="WOrmMongodb.html#.delAllGfs">delAllGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.delGfs">delGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.insert">insert</a></li><li data-type='method'><a href="WOrmMongodb.html#.insertGfs">insertGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.save">save</a></li><li data-type='method'><a href="WOrmMongodb.html#.select">select</a></li><li data-type='method'><a href="WOrmMongodb.html#.selectByPk">selectByPk</a></li><li data-type='method'><a href="WOrmMongodb.html#.selectByPkGfs">selectByPkGfs</a></li></ul></li></ul>
33
33
 
34
34
  </nav>
35
35
 
@@ -67,6 +67,9 @@ import pmSeries from 'wsemi/src/pmSeries.mjs'
67
67
  /**
68
68
  * 操作資料庫(MongoDB)
69
69
  *
70
+ * 本套件之主鍵欄位固定為id,尚未支援由呼叫端指定。
71
+ * id為無業務語義之識別碼,故insert與save於輸入未帶有效id時自動補值;del不補值。
72
+ *
70
73
  * @class
71
74
  * @param {Object} [opt={}] 輸入設定物件,預設{}
72
75
  * @param {String} [opt.url='mongodb://127.0.0.1:27017'] 輸入連接資料庫字串,預設'mongodb://127.0.0.1:27017'
@@ -321,19 +324,20 @@ function WOrmMongodb(opt = {}) {
321
324
 
322
325
 
323
326
  /**
324
- * 由id查詢單筆數據,因由MongoDB查找且僅回傳單筆,不需如select提取全部符合數據再處理,故數據量大時效能較佳
327
+ * 由主鍵查詢單筆數據,因由MongoDB查找且僅回傳單筆,不需如select提取全部符合數據再處理,故數據量大時效能較佳
328
+ * 註: 本套件之主鍵欄位固定為id,尚未支援由呼叫端指定
325
329
  * 註: 本函數不得有副作用,故不建立唯一索引
326
330
  *
327
331
  * @memberOf WOrmMongodb
328
- * @param {String} id 輸入id字串
329
- * @returns {Promise} 回傳Promise,resolve回傳數據物件,若無此id或id無效則回傳null,reject回傳錯誤訊息
332
+ * @param {String} pk 輸入主鍵值字串,即數據之id
333
+ * @returns {Promise} 回傳Promise,resolve回傳數據物件,若無此主鍵或主鍵值無效則回傳null,reject回傳錯誤訊息
330
334
  */
331
- async function selectById(id) {
335
+ async function selectByPk(pk) {
332
336
  let isErr = false
333
337
 
334
338
  //check
335
- if (!isestr(id)) {
336
- //未給有效id視為查無數據, 判定基準與insert、save、del內對id之認定一致
339
+ if (!isestr(pk)) {
340
+ //未給有效主鍵值視為查無數據, 判定基準與insert、save、del內對id之認定一致
337
341
  return null
338
342
  }
339
343
 
@@ -349,7 +353,7 @@ function WOrmMongodb(opt = {}) {
349
353
  let collection = database.collection(opt.cl)
350
354
 
351
355
  //findOne, 以投影去除_id, 令回傳形狀與select一致
352
- let v = await collection.findOne({ id }, { projection: { _id: 0 } })
356
+ let v = await collection.findOne({ id: pk }, { projection: { _id: 0 } })
353
357
 
354
358
  //check, 判定基準與insert、save、del內對既有數據之認定一致
355
359
  if (iseobj(v)) {
@@ -956,20 +960,21 @@ function WOrmMongodb(opt = {}) {
956
960
 
957
961
 
958
962
  /**
959
- * 使用GridFS,由id查詢單筆數據
960
- * 註: 查無數據或id無效時回傳null,判定基準與selectById一致
963
+ * 使用GridFS,由主鍵查詢單筆數據
964
+ * 註: 查無數據或主鍵值無效時回傳null,判定基準與selectByPk一致
965
+ * 註: 本套件之主鍵欄位固定為id,尚未支援由呼叫端指定
961
966
  * 本函數不得有副作用,故不建立唯一索引
962
967
  *
963
968
  * @memberOf WOrmMongodb
964
- * @param {String} id 輸入查詢id字串
965
- * @returns {Promise} 回傳Promise,resolve回傳數據物件{ id, u8a },若無此id或id無效則回傳null,reject回傳錯誤訊息
969
+ * @param {String} pk 輸入主鍵值字串,即數據之id
970
+ * @returns {Promise} 回傳Promise,resolve回傳數據物件{ id, u8a },若無此主鍵或主鍵值無效則回傳null,reject回傳錯誤訊息
966
971
  */
967
- async function selectByIdGfs(id) {
972
+ async function selectByPkGfs(pk) {
968
973
  let isErr = false
969
974
 
970
975
  //check
971
- if (!isestr(id)) {
972
- //未給有效id視為查無數據, 判定基準與selectById一致
976
+ if (!isestr(pk)) {
977
+ //未給有效主鍵值視為查無數據, 判定基準與selectByPk一致
973
978
  return null
974
979
  }
975
980
 
@@ -1026,11 +1031,11 @@ function WOrmMongodb(opt = {}) {
1026
1031
  try {
1027
1032
 
1028
1033
  //core
1029
- let u8a = await core(id)
1034
+ let u8a = await core(pk)
1030
1035
 
1031
1036
  //res, 形狀與insertGfs所收之數據物件一致
1032
1037
  res = {
1033
- id,
1038
+ id: pk,
1034
1039
  u8a,
1035
1040
  }
1036
1041
 
@@ -1287,12 +1292,12 @@ function WOrmMongodb(opt = {}) {
1287
1292
 
1288
1293
  //bind
1289
1294
  ee.select = select
1290
- ee.selectById = selectById
1295
+ ee.selectByPk = selectByPk
1291
1296
  ee.insert = insert
1292
1297
  ee.save = save
1293
1298
  ee.del = del
1294
1299
  ee.delAll = delAll
1295
- ee.selectByIdGfs = selectByIdGfs
1300
+ ee.selectByPkGfs = selectByPkGfs
1296
1301
  ee.insertGfs = insertGfs
1297
1302
  ee.delGfs = delGfs
1298
1303
  ee.delAllGfs = delAllGfs
@@ -1317,7 +1322,7 @@ export default WOrmMongodb
1317
1322
  <br class="clear">
1318
1323
 
1319
1324
  <footer>
1320
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Aug 16 2026 22:37:44 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1325
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Aug 16 2026 23:36:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1321
1326
  </footer>
1322
1327
 
1323
1328
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -29,7 +29,7 @@
29
29
  <nav >
30
30
 
31
31
 
32
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WOrmMongodb.html">WOrmMongodb</a><ul class='methods'><li data-type='method'><a href="WOrmMongodb.html#.del">del</a></li><li data-type='method'><a href="WOrmMongodb.html#.delAll">delAll</a></li><li data-type='method'><a href="WOrmMongodb.html#.delAllGfs">delAllGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.delGfs">delGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.insert">insert</a></li><li data-type='method'><a href="WOrmMongodb.html#.insertGfs">insertGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.save">save</a></li><li data-type='method'><a href="WOrmMongodb.html#.select">select</a></li><li data-type='method'><a href="WOrmMongodb.html#.selectById">selectById</a></li><li data-type='method'><a href="WOrmMongodb.html#.selectByIdGfs">selectByIdGfs</a></li></ul></li></ul>
32
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WOrmMongodb.html">WOrmMongodb</a><ul class='methods'><li data-type='method'><a href="WOrmMongodb.html#.del">del</a></li><li data-type='method'><a href="WOrmMongodb.html#.delAll">delAll</a></li><li data-type='method'><a href="WOrmMongodb.html#.delAllGfs">delAllGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.delGfs">delGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.insert">insert</a></li><li data-type='method'><a href="WOrmMongodb.html#.insertGfs">insertGfs</a></li><li data-type='method'><a href="WOrmMongodb.html#.save">save</a></li><li data-type='method'><a href="WOrmMongodb.html#.select">select</a></li><li data-type='method'><a href="WOrmMongodb.html#.selectByPk">selectByPk</a></li><li data-type='method'><a href="WOrmMongodb.html#.selectByPkGfs">selectByPkGfs</a></li></ul></li></ul>
33
33
 
34
34
  </nav>
35
35
 
@@ -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 22:37:44 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 Sun Aug 16 2026 23:36:47 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
@@ -102,13 +102,13 @@ async function test() {
102
102
  let sr = await wo.select({ name: { $regex: 'PeT', $options: 'i' } })
103
103
  console.log('selectReg', sr)
104
104
 
105
- //selectById, 由id直接查找單筆, 不需如select提取全部符合數據再處理
106
- let sbi = await wo.selectById('id-rosemary')
107
- console.log('selectById', sbi)
105
+ //selectByPk, 由id直接查找單筆, 不需如select提取全部符合數據再處理
106
+ let sbi = await wo.selectByPk('id-rosemary')
107
+ console.log('selectByPk', sbi)
108
108
 
109
- //selectById by id not existed
110
- let sbn = await wo.selectById('id-not-existed')
111
- console.log('selectById by id not existed', sbn)
109
+ //selectByPk by id not existed
110
+ let sbn = await wo.selectByPk('id-not-existed')
111
+ console.log('selectByPk by id not existed', sbn)
112
112
 
113
113
  //del
114
114
  let d = ss.filter(function(v) {
@@ -165,8 +165,8 @@ test()
165
165
  // }
166
166
  // ]
167
167
  // selectReg [ { id: 'id-peter', name: 'peter(modify)', value: 123 } ]
168
- // selectById { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
169
- // selectById by id not existed null
168
+ // selectByPk { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
169
+ // selectByPk by id not existed null
170
170
  // change del
171
171
  // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
172
172
 
package/g-gfs.mjs CHANGED
@@ -49,15 +49,15 @@ async function test() {
49
49
  let gr = await wo.insertGfs({ id: 'id-file', u8a: genU8a(50) })
50
50
  console.log('insertGfs existed id', gr)
51
51
 
52
- //selectByIdGfs
53
- let gs = await wo.selectByIdGfs('id-file')
54
- console.log('selectByIdGfs id', gs.id)
55
- console.log('selectByIdGfs u8a.length', gs.u8a.length)
56
- console.log('selectByIdGfs u8a[0..3]', gs.u8a[0], gs.u8a[1], gs.u8a[2], gs.u8a[3])
52
+ //selectByPkGfs
53
+ let gs = await wo.selectByPkGfs('id-file')
54
+ console.log('selectByPkGfs id', gs.id)
55
+ console.log('selectByPkGfs u8a.length', gs.u8a.length)
56
+ console.log('selectByPkGfs u8a[0..3]', gs.u8a[0], gs.u8a[1], gs.u8a[2], gs.u8a[3])
57
57
 
58
- //selectByIdGfs by id not existed
59
- let gn = await wo.selectByIdGfs('id-not-existed')
60
- console.log('selectByIdGfs by id not existed', gn)
58
+ //selectByPkGfs by id not existed
59
+ let gn = await wo.selectByPkGfs('id-not-existed')
60
+ console.log('selectByPkGfs by id not existed', gn)
61
61
 
62
62
  //insertGfs, 一次插入多筆
63
63
  let gm = await wo.insertGfs([
@@ -86,10 +86,10 @@ test()
86
86
  // insertGfs { n: 1, nInserted: 1, ok: 1 }
87
87
  // change insertGfs
88
88
  // insertGfs existed id { n: 1, nInserted: 0, ok: 1 }
89
- // selectByIdGfs id id-file
90
- // selectByIdGfs u8a.length 1000
91
- // selectByIdGfs u8a[0..3] 0 1 2 3
92
- // selectByIdGfs by id not existed null
89
+ // selectByPkGfs id id-file
90
+ // selectByPkGfs u8a.length 1000
91
+ // selectByPkGfs u8a[0..3] 0 1 2 3
92
+ // selectByPkGfs by id not existed null
93
93
  // change insertGfs
94
94
  // insertGfs multi { n: 2, nInserted: 2, ok: 1 }
95
95
  // change delGfs
package/g-unique.mjs CHANGED
@@ -28,12 +28,12 @@ async function test() {
28
28
  { id: 'id-uniq', name: 'uniq' },
29
29
  ])
30
30
  console.log('insert with duplicated id', ri)
31
- console.log('selectById(id-dup)', await wo.selectById('id-dup'))
31
+ console.log('selectByPk(id-dup)', await wo.selectByPk('id-dup'))
32
32
 
33
33
  //insert, 對已存在id再插入則跳過而不覆寫
34
34
  let re = await wo.insert({ id: 'id-dup', name: 'dup-3' })
35
35
  console.log('insert existed id', re)
36
- console.log('selectById(id-dup)', await wo.selectById('id-dup'))
36
+ console.log('selectByPk(id-dup)', await wo.selectByPk('id-dup'))
37
37
 
38
38
  //insert, 併發對同一id插入10次, nInserted總和為1
39
39
  let rc = await Promise.all(Array.from({ length: 10 }, (v, k) => {
@@ -48,19 +48,19 @@ async function test() {
48
48
  }))
49
49
  console.log('count of nInserted===1 by 5 concurrent save', rs.filter((v) => v[0].nInserted === 1).length)
50
50
  console.log('records of id-new', (await wo.select({ id: 'id-new' })).length)
51
- console.log('selectById(id-new)', await wo.selectById('id-new'))
51
+ console.log('selectByPk(id-new)', await wo.selectByPk('id-new'))
52
52
 
53
53
  }
54
54
  test()
55
55
  // insert with duplicated id { n: 3, nInserted: 2, ok: 1 }
56
- // selectById(id-dup) { id: 'id-dup', name: 'dup-1' }
56
+ // selectByPk(id-dup) { id: 'id-dup', name: 'dup-1' }
57
57
  // insert existed id { n: 1, nInserted: 0, ok: 1 }
58
- // selectById(id-dup) { id: 'id-dup', name: 'dup-1' }
58
+ // selectByPk(id-dup) { id: 'id-dup', name: 'dup-1' }
59
59
  // sum of nInserted by 10 concurrent insert 1
60
60
  // records of id-race 1
61
61
  // count of nInserted===1 by 5 concurrent save 1
62
62
  // records of id-new 1
63
- // selectById(id-new) { id: 'id-new', f0: 0, f1: 1, f2: 2, f4: 4, f3: 3 }
63
+ // selectByPk(id-new) { id: 'id-new', f0: 0, f1: 1, f2: 2, f4: 4, f3: 3 }
64
64
  // 註: 併發儲存之各欄位皆會保留, 惟欄位順序取決於各次儲存之完成順序, 故每次執行不盡相同
65
65
 
66
66
  //node g-unique.mjs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w-orm-mongodb",
3
- "version": "1.1.38",
3
+ "version": "1.1.39",
4
4
  "main": "dist/w-orm-mongodb.umd.js",
5
5
  "dependencies": {
6
6
  "mongodb": "^7.5.0",
@@ -20,6 +20,9 @@ import pmSeries from 'wsemi/src/pmSeries.mjs'
20
20
  /**
21
21
  * 操作資料庫(MongoDB)
22
22
  *
23
+ * 本套件之主鍵欄位固定為id,尚未支援由呼叫端指定。
24
+ * id為無業務語義之識別碼,故insert與save於輸入未帶有效id時自動補值;del不補值。
25
+ *
23
26
  * @class
24
27
  * @param {Object} [opt={}] 輸入設定物件,預設{}
25
28
  * @param {String} [opt.url='mongodb://127.0.0.1:27017'] 輸入連接資料庫字串,預設'mongodb://127.0.0.1:27017'
@@ -274,19 +277,20 @@ function WOrmMongodb(opt = {}) {
274
277
 
275
278
 
276
279
  /**
277
- * 由id查詢單筆數據,因由MongoDB查找且僅回傳單筆,不需如select提取全部符合數據再處理,故數據量大時效能較佳
280
+ * 由主鍵查詢單筆數據,因由MongoDB查找且僅回傳單筆,不需如select提取全部符合數據再處理,故數據量大時效能較佳
281
+ * 註: 本套件之主鍵欄位固定為id,尚未支援由呼叫端指定
278
282
  * 註: 本函數不得有副作用,故不建立唯一索引
279
283
  *
280
284
  * @memberOf WOrmMongodb
281
- * @param {String} id 輸入id字串
282
- * @returns {Promise} 回傳Promise,resolve回傳數據物件,若無此id或id無效則回傳null,reject回傳錯誤訊息
285
+ * @param {String} pk 輸入主鍵值字串,即數據之id
286
+ * @returns {Promise} 回傳Promise,resolve回傳數據物件,若無此主鍵或主鍵值無效則回傳null,reject回傳錯誤訊息
283
287
  */
284
- async function selectById(id) {
288
+ async function selectByPk(pk) {
285
289
  let isErr = false
286
290
 
287
291
  //check
288
- if (!isestr(id)) {
289
- //未給有效id視為查無數據, 判定基準與insert、save、del內對id之認定一致
292
+ if (!isestr(pk)) {
293
+ //未給有效主鍵值視為查無數據, 判定基準與insert、save、del內對id之認定一致
290
294
  return null
291
295
  }
292
296
 
@@ -302,7 +306,7 @@ function WOrmMongodb(opt = {}) {
302
306
  let collection = database.collection(opt.cl)
303
307
 
304
308
  //findOne, 以投影去除_id, 令回傳形狀與select一致
305
- let v = await collection.findOne({ id }, { projection: { _id: 0 } })
309
+ let v = await collection.findOne({ id: pk }, { projection: { _id: 0 } })
306
310
 
307
311
  //check, 判定基準與insert、save、del內對既有數據之認定一致
308
312
  if (iseobj(v)) {
@@ -909,20 +913,21 @@ function WOrmMongodb(opt = {}) {
909
913
 
910
914
 
911
915
  /**
912
- * 使用GridFS,由id查詢單筆數據
913
- * 註: 查無數據或id無效時回傳null,判定基準與selectById一致
916
+ * 使用GridFS,由主鍵查詢單筆數據
917
+ * 註: 查無數據或主鍵值無效時回傳null,判定基準與selectByPk一致
918
+ * 註: 本套件之主鍵欄位固定為id,尚未支援由呼叫端指定
914
919
  * 本函數不得有副作用,故不建立唯一索引
915
920
  *
916
921
  * @memberOf WOrmMongodb
917
- * @param {String} id 輸入查詢id字串
918
- * @returns {Promise} 回傳Promise,resolve回傳數據物件{ id, u8a },若無此id或id無效則回傳null,reject回傳錯誤訊息
922
+ * @param {String} pk 輸入主鍵值字串,即數據之id
923
+ * @returns {Promise} 回傳Promise,resolve回傳數據物件{ id, u8a },若無此主鍵或主鍵值無效則回傳null,reject回傳錯誤訊息
919
924
  */
920
- async function selectByIdGfs(id) {
925
+ async function selectByPkGfs(pk) {
921
926
  let isErr = false
922
927
 
923
928
  //check
924
- if (!isestr(id)) {
925
- //未給有效id視為查無數據, 判定基準與selectById一致
929
+ if (!isestr(pk)) {
930
+ //未給有效主鍵值視為查無數據, 判定基準與selectByPk一致
926
931
  return null
927
932
  }
928
933
 
@@ -979,11 +984,11 @@ function WOrmMongodb(opt = {}) {
979
984
  try {
980
985
 
981
986
  //core
982
- let u8a = await core(id)
987
+ let u8a = await core(pk)
983
988
 
984
989
  //res, 形狀與insertGfs所收之數據物件一致
985
990
  res = {
986
- id,
991
+ id: pk,
987
992
  u8a,
988
993
  }
989
994
 
@@ -1240,12 +1245,12 @@ function WOrmMongodb(opt = {}) {
1240
1245
 
1241
1246
  //bind
1242
1247
  ee.select = select
1243
- ee.selectById = selectById
1248
+ ee.selectByPk = selectByPk
1244
1249
  ee.insert = insert
1245
1250
  ee.save = save
1246
1251
  ee.del = del
1247
1252
  ee.delAll = delAll
1248
- ee.selectByIdGfs = selectByIdGfs
1253
+ ee.selectByPkGfs = selectByPkGfs
1249
1254
  ee.insertGfs = insertGfs
1250
1255
  ee.delGfs = delGfs
1251
1256
  ee.delAllGfs = delAllGfs
@@ -296,10 +296,10 @@ describe('basic', function() {
296
296
  // vans[17] = []
297
297
  vget[17] = await wo.select({ name: 'not-existed' })
298
298
 
299
- //selectById, 由id直接查找單筆
299
+ //selectByPk, 由id直接查找單筆
300
300
  rt = null
301
301
  // vans[10] = { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
302
- await wo.selectById('id-rosemary')
302
+ await wo.selectByPk('id-rosemary')
303
303
  .then(function(msg) {
304
304
  rt = msg
305
305
  })
@@ -308,16 +308,16 @@ describe('basic', function() {
308
308
  })
309
309
  vget[10] = rt
310
310
 
311
- //selectById, 與select(find)取得同一筆之內容須一致
311
+ //selectByPk, 與select(find)取得同一筆之內容須一致
312
312
  // vans[11] = true
313
- let sbi = await wo.selectById('id-peter')
313
+ let sbi = await wo.selectByPk('id-peter')
314
314
  let sbf = await wo.select({ id: 'id-peter' })
315
315
  vget[11] = JSON.stringify(sbi) === JSON.stringify(sbf[0])
316
316
 
317
- //selectById by id not existed
317
+ //selectByPk by id not existed
318
318
  rt = null
319
319
  // vans[12] = null
320
- await wo.selectById('id-not-existed')
320
+ await wo.selectByPk('id-not-existed')
321
321
  .then(function(msg) {
322
322
  rt = msg
323
323
  })
@@ -326,12 +326,12 @@ describe('basic', function() {
326
326
  })
327
327
  vget[12] = rt
328
328
 
329
- //selectById by id invalid, 未給有效id視為查無數據
329
+ //selectByPk by id invalid, 未給有效id視為查無數據
330
330
  // vans[13] = [null, null, null]
331
331
  vget[13] = [
332
- await wo.selectById(''),
333
- await wo.selectById(123),
334
- await wo.selectById(null),
332
+ await wo.selectByPk(''),
333
+ await wo.selectByPk(123),
334
+ await wo.selectByPk(null),
335
335
  ]
336
336
 
337
337
  //del
@@ -349,9 +349,9 @@ describe('basic', function() {
349
349
  })
350
350
  vget[14] = rt
351
351
 
352
- //selectById, 已刪除者須回傳null
352
+ //selectByPk, 已刪除者須回傳null
353
353
  // vans[15] = null
354
- vget[15] = await wo.selectById(d[0].id)
354
+ vget[15] = await wo.selectByPk(d[0].id)
355
355
 
356
356
  })
357
357
 
@@ -422,22 +422,22 @@ describe('basic', function() {
422
422
  })
423
423
 
424
424
  vans[10] = { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
425
- it(`should get ${JSON.stringify(vans[10])} for selectById`, async function() {
425
+ it(`should get ${JSON.stringify(vans[10])} for selectByPk`, async function() {
426
426
  assert.strict.deepStrictEqual(vget[10], vans[10])
427
427
  })
428
428
 
429
429
  vans[11] = true
430
- it(`should get ${JSON.stringify(vans[11])} for same content between selectById and select`, async function() {
430
+ it(`should get ${JSON.stringify(vans[11])} for same content between selectByPk and select`, async function() {
431
431
  assert.strict.deepStrictEqual(vget[11], vans[11])
432
432
  })
433
433
 
434
434
  vans[12] = null
435
- it(`should get ${JSON.stringify(vans[12])} for selectById by id not existed`, async function() {
435
+ it(`should get ${JSON.stringify(vans[12])} for selectByPk by id not existed`, async function() {
436
436
  assert.strict.deepStrictEqual(vget[12], vans[12])
437
437
  })
438
438
 
439
439
  vans[13] = [null, null, null]
440
- it(`should get ${JSON.stringify(vans[13])} for selectById by id invalid`, async function() {
440
+ it(`should get ${JSON.stringify(vans[13])} for selectByPk by id invalid`, async function() {
441
441
  assert.strict.deepStrictEqual(vget[13], vans[13])
442
442
  })
443
443
 
@@ -447,7 +447,7 @@ describe('basic', function() {
447
447
  })
448
448
 
449
449
  vans[15] = null
450
- it(`should get ${JSON.stringify(vans[15])} for selectById after del`, async function() {
450
+ it(`should get ${JSON.stringify(vans[15])} for selectByPk after del`, async function() {
451
451
  assert.strict.deepStrictEqual(vget[15], vans[15])
452
452
  })
453
453
 
@@ -510,10 +510,10 @@ describe('insert', function() {
510
510
  vget[7] = (await wo.select()).length
511
511
 
512
512
  //同批重複者僅首筆入庫
513
- vget[8] = (await wo.selectById('i-dup')).name
513
+ vget[8] = (await wo.selectByPk('i-dup')).name
514
514
 
515
515
  //已存在id不得被insert覆寫
516
- vget[9] = await wo.selectById('i2')
516
+ vget[9] = await wo.selectByPk('i2')
517
517
 
518
518
  //併發後僅存單筆
519
519
  vget[10] = (await wo.select({ id: 'i-race' })).length
@@ -605,7 +605,7 @@ describe('save', function() {
605
605
  await Promise.all(Array.from({ length: 10 }, (v, k) => {
606
606
  return wo.save({ id: 'u1', [`f${k}`]: k })
607
607
  }))
608
- let vu1 = await wo.selectById('u1')
608
+ let vu1 = await wo.selectByPk('u1')
609
609
  vget[1] = Object.keys(vu1).filter((k) => k.indexOf('f') === 0).length
610
610
  vget[2] = vu1.base
611
611
 
@@ -616,7 +616,7 @@ describe('save', function() {
616
616
  vget[3] = rsn.filter((v) => v[0].nInserted === 1).length
617
617
  vget[4] = rsn.filter((v) => v[0].ok !== 1).length
618
618
  vget[5] = (await wo.select({ id: 'w1' })).length
619
- vget[6] = Object.keys(await wo.selectById('w1')).filter((k) => k.indexOf('g') === 0).length
619
+ vget[6] = Object.keys(await wo.selectByPk('w1')).filter((k) => k.indexOf('g') === 0).length
620
620
 
621
621
  //save內容相同不更新, 由MongoDB於伺服器端比對合併後結果與現值
622
622
  await wo.insert({ id: 's1', name: 'same', value: 5 })
@@ -633,11 +633,11 @@ describe('save', function() {
633
633
  //save內容不同須更新, 未給之欄位須保留
634
634
  await wo.insert({ id: 'd1', name: 'diff', value: 5 })
635
635
  vget[8] = await wo.save({ id: 'd1', value: 6 })
636
- vget[9] = await wo.selectById('d1')
636
+ vget[9] = await wo.selectByPk('d1')
637
637
 
638
638
  //save(autoInsert=false)對不存在之id不得插入
639
639
  vget[10] = await wo.save({ id: 'n1', name: 'none' }, { autoInsert: false })
640
- vget[11] = await wo.selectById('n1')
640
+ vget[11] = await wo.selectByPk('n1')
641
641
 
642
642
  //併發save(autoInsert=false)對既有id之不同欄位, 各欄位皆須保留且不得報錯
643
643
  await wo.insert({ id: 'p1', name: 'origin', value: 1 })
@@ -646,7 +646,7 @@ describe('save', function() {
646
646
  wo.save({ id: 'p1', value: 88 }, { autoInsert: false }),
647
647
  ])
648
648
  vget[12] = rsu.filter((v) => v[0].ok !== 1).length
649
- vget[13] = await wo.selectById('p1')
649
+ vget[13] = await wo.selectByPk('p1')
650
650
 
651
651
  //change事件, autoInsert時仍須發出insert事件
652
652
  let woEv = WOrm(genOpt('saveevent'))
@@ -812,10 +812,10 @@ describe('save single failure', function() {
812
812
  }
813
813
 
814
814
  //單筆失敗不得中斷整批, 後續筆仍須寫入
815
- vget[7] = (await wo.selectById('f3')).name
815
+ vget[7] = (await wo.selectByPk('f3')).name
816
816
 
817
817
  //失敗筆不得被寫入
818
- vget[8] = await wo.selectById('f2')
818
+ vget[8] = await wo.selectByPk('f2')
819
819
 
820
820
  })
821
821
 
@@ -920,7 +920,7 @@ describe('del', function() {
920
920
  vget[15] = typeof rbig[0].err === 'string' && rbig[0].err.length > 0
921
921
 
922
922
  //單筆失敗不得中斷整批, 後續筆仍須刪除
923
- vget[16] = await wo.selectById('k3')
923
+ vget[16] = await wo.selectByPk('k3')
924
924
 
925
925
  })
926
926
 
@@ -1094,7 +1094,7 @@ describe('change event', function() {
1094
1094
  })
1095
1095
 
1096
1096
  vget[1] = await wo.insert({ id: 'e1', name: 'a' })
1097
- vget[2] = await wo.selectById('e1')
1097
+ vget[2] = await wo.selectByPk('e1')
1098
1098
  vget[3] = await wo.save({ id: 'e1', name: 'b' })
1099
1099
  vget[4] = await wo.del({ id: 'e1' })
1100
1100
  vget[5] = await wo.delAll()
@@ -1160,7 +1160,7 @@ describe('cross process concurrency', function() {
1160
1160
  runProc('P1', clSav, 'save', keys),
1161
1161
  runProc('P2', clSav, 'save', keys),
1162
1162
  ])
1163
- let vx1 = await woSav.selectById('x1')
1163
+ let vx1 = await woSav.selectByPk('x1')
1164
1164
  vget[4] = Object.keys(vx1).filter((k) => k.indexOf('P1k') === 0 || k.indexOf('P2k') === 0).length
1165
1165
  vget[5] = vx1.base
1166
1166
  vget[6] = (await woSav.select()).length
@@ -139,10 +139,10 @@ describe('gfs basic', function() {
139
139
  // vans[3] = { files: 1, chunks: 2 }
140
140
  vget[3] = await countDocs(cl)
141
141
 
142
- //selectByIdGfs, 取回內容須與來源逐位元組相同, 且形狀與insertGfs所收之數據物件一致
142
+ //selectByPkGfs, 取回內容須與來源逐位元組相同, 且形狀與insertGfs所收之數據物件一致
143
143
  rt = null
144
144
  // vans[4] = { keys: 'id,u8a', id: 'g-big', length: nSize, hash, b0: 0, b1: 1, b255: 255, b256: 0 }
145
- await wo.selectByIdGfs('g-big')
145
+ await wo.selectByPkGfs('g-big')
146
146
  .then(function(msg) {
147
147
  rt = {
148
148
  keys: genKeys(msg),
@@ -160,10 +160,10 @@ describe('gfs basic', function() {
160
160
  })
161
161
  vget[4] = rt
162
162
 
163
- //selectByIdGfs by id not existed
163
+ //selectByPkGfs by id not existed
164
164
  rt = null
165
165
  // vans[5] = null
166
- await wo.selectByIdGfs('id-not-existed')
166
+ await wo.selectByPkGfs('id-not-existed')
167
167
  .then(function(msg) {
168
168
  rt = msg
169
169
  })
@@ -172,12 +172,12 @@ describe('gfs basic', function() {
172
172
  })
173
173
  vget[5] = rt
174
174
 
175
- //selectByIdGfs by id invalid, 未給有效id視為查無數據
175
+ //selectByPkGfs by id invalid, 未給有效id視為查無數據
176
176
  // vans[6] = [null, null, null]
177
177
  vget[6] = [
178
- await wo.selectByIdGfs(''),
179
- await wo.selectByIdGfs(123),
180
- await wo.selectByIdGfs(null),
178
+ await wo.selectByPkGfs(''),
179
+ await wo.selectByPkGfs(123),
180
+ await wo.selectByPkGfs(null),
181
181
  ]
182
182
 
183
183
  //insertGfs未給id時自動產生
@@ -284,17 +284,17 @@ describe('gfs basic', function() {
284
284
  b255: 255,
285
285
  b256: 0,
286
286
  }
287
- it(`should get same content for selectByIdGfs`, async function() {
287
+ it(`should get same content for selectByPkGfs`, async function() {
288
288
  assert.strict.deepStrictEqual(vget[4], vans[4])
289
289
  })
290
290
 
291
291
  vans[5] = null
292
- it(`should get ${JSON.stringify(vans[5])} for selectByIdGfs by id not existed`, async function() {
292
+ it(`should get ${JSON.stringify(vans[5])} for selectByPkGfs by id not existed`, async function() {
293
293
  assert.strict.deepStrictEqual(vget[5], vans[5])
294
294
  })
295
295
 
296
296
  vans[6] = [null, null, null]
297
- it(`should get ${JSON.stringify(vans[6])} for selectByIdGfs by id invalid`, async function() {
297
+ it(`should get ${JSON.stringify(vans[6])} for selectByPkGfs by id invalid`, async function() {
298
298
  assert.strict.deepStrictEqual(vget[6], vans[6])
299
299
  })
300
300
 
@@ -395,7 +395,7 @@ describe('gfs insert', function() {
395
395
  vget[3] = { files: c2.files - c1.files, chunks: c2.chunks - c1.chunks }
396
396
 
397
397
  //已存在id不得被覆寫, 內容須為首次所給
398
- let vi1 = await wo.selectByIdGfs('i1')
398
+ let vi1 = await wo.selectByPkGfs('i1')
399
399
  vget[4] = genHash(vi1.u8a) === genHash(genU8a(100, 1))
400
400
 
401
401
  //部份重複, 1筆已存在2筆為新
@@ -411,7 +411,7 @@ describe('gfs insert', function() {
411
411
  { id: 'i-dup', u8a: genU8a(100, 7) },
412
412
  { id: 'i-uniq', u8a: genU8a(100, 8) },
413
413
  ])
414
- let vdup = await wo.selectByIdGfs('i-dup')
414
+ let vdup = await wo.selectByPkGfs('i-dup')
415
415
  vget[7] = genHash(vdup.u8a) === genHash(genU8a(100, 6))
416
416
 
417
417
  //併發對同一id插入10次, nInserted總和須為1
@@ -545,7 +545,7 @@ describe('gfs change event', function() {
545
545
  })
546
546
 
547
547
  vget[1] = await wo.insertGfs({ id: 'e1', u8a: genU8a(100, 1) })
548
- vget[2] = genHash((await wo.selectByIdGfs('e1')).u8a) === genHash(genU8a(100, 1))
548
+ vget[2] = genHash((await wo.selectByPkGfs('e1')).u8a) === genHash(genU8a(100, 1))
549
549
  vget[3] = await wo.delGfs({ id: 'e1' })
550
550
  vget[4] = await wo.delAllGfs()
551
551