w-orm-lmdb 1.0.4 → 1.0.6

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.
@@ -80,7 +80,7 @@
80
80
 
81
81
  <dt class="tag-source">Source:</dt>
82
82
  <dd class="tag-source"><ul class="dummy"><li>
83
- <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line32">line 32</a>
83
+ <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line34">line 34</a>
84
84
  </li></ul></dd>
85
85
 
86
86
 
@@ -336,6 +336,46 @@
336
336
  </tr>
337
337
 
338
338
 
339
+
340
+ <tr>
341
+
342
+ <td class="name"><code>useCache</code></td>
343
+
344
+
345
+ <td class="type">
346
+
347
+
348
+ <span class="param-type">Boolean</span>
349
+
350
+
351
+
352
+
353
+ </td>
354
+
355
+
356
+ <td class="attributes">
357
+
358
+ &lt;optional><br>
359
+
360
+
361
+
362
+
363
+
364
+ </td>
365
+
366
+
367
+
368
+ <td class="default">
369
+
370
+ <code>false</code>
371
+
372
+ </td>
373
+
374
+
375
+ <td class="description last"><p>輸入是否使用select快取,適用於單程序操作,預設false</p></td>
376
+ </tr>
377
+
378
+
339
379
  </tbody>
340
380
  </table>
341
381
 
@@ -429,7 +469,7 @@
429
469
 
430
470
  <dt class="tag-source">Source:</dt>
431
471
  <dd class="tag-source"><ul class="dummy"><li>
432
- <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line397">line 397</a>
472
+ <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line416">line 416</a>
433
473
  </li></ul></dd>
434
474
 
435
475
 
@@ -590,7 +630,7 @@
590
630
 
591
631
  <dt class="tag-source">Source:</dt>
592
632
  <dd class="tag-source"><ul class="dummy"><li>
593
- <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line512">line 512</a>
633
+ <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line531">line 531</a>
594
634
  </li></ul></dd>
595
635
 
596
636
 
@@ -768,7 +808,7 @@
768
808
 
769
809
  <dt class="tag-source">Source:</dt>
770
810
  <dd class="tag-source"><ul class="dummy"><li>
771
- <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line177">line 177</a>
811
+ <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line186">line 186</a>
772
812
  </li></ul></dd>
773
813
 
774
814
 
@@ -929,7 +969,7 @@
929
969
 
930
970
  <dt class="tag-source">Source:</dt>
931
971
  <dd class="tag-source"><ul class="dummy"><li>
932
- <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line280">line 280</a>
972
+ <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line289">line 289</a>
933
973
  </li></ul></dd>
934
974
 
935
975
 
@@ -1216,7 +1256,7 @@
1216
1256
 
1217
1257
  <dt class="tag-source">Source:</dt>
1218
1258
  <dd class="tag-source"><ul class="dummy"><li>
1219
- <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line123">line 123</a>
1259
+ <a href="WOrmLmdb.mjs.html">WOrmLmdb.mjs</a>, <a href="WOrmLmdb.mjs.html#line132">line 132</a>
1220
1260
  </li></ul></dd>
1221
1261
 
1222
1262
 
@@ -1393,7 +1433,7 @@
1393
1433
  <br class="clear">
1394
1434
 
1395
1435
  <footer>
1396
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Thu May 14 2026 16:50:25 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1436
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri May 15 2026 13:14:13 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1397
1437
  </footer>
1398
1438
 
1399
1439
  <script>prettyPrint();</script>
@@ -59,6 +59,7 @@ import isestr from 'wsemi/src/isestr.mjs'
59
59
  import isarr from 'wsemi/src/isarr.mjs'
60
60
  import isearr from 'wsemi/src/isearr.mjs'
61
61
  import iseobj from 'wsemi/src/iseobj.mjs'
62
+ import isbol from 'wsemi/src/isbol.mjs'
62
63
  import haskey from 'wsemi/src/haskey.mjs'
63
64
  import evem from 'wsemi/src/evem.mjs'
64
65
  import genIDSeq from 'wsemi/src/genIDSeq.mjs'
@@ -74,6 +75,7 @@ import waitFun from 'wsemi/src/waitFun.mjs'
74
75
  * @param {String} [opt.url='_db'] 輸入資料庫用資料夾字串,預設'_db'
75
76
  * @param {String} [opt.db='worm'] 輸入使用資料庫名稱字串,預設'worm'
76
77
  * @param {String} [opt.cl='test'] 輸入使用資料表名稱字串,預設'test'
78
+ * @param {Boolean} [opt.useCache=false] 輸入是否使用select快取,適用於單程序操作,預設false
77
79
  * @returns {Object} 回傳操作資料庫物件,各事件功能詳見說明
78
80
  */
79
81
  function WOrmLmdb(opt = {}) {
@@ -99,6 +101,12 @@ function WOrmLmdb(opt = {}) {
99
101
  cl = 'test'
100
102
  }
101
103
 
104
+ //useCache
105
+ let useCache = get(opt, 'useCache')
106
+ if (!isbol(useCache)) {
107
+ useCache = false
108
+ }
109
+
102
110
  //storage
103
111
  let storage = `${url}/${db}/${cl}`
104
112
  // console.log('storage',storage)
@@ -117,7 +125,7 @@ function WOrmLmdb(opt = {}) {
117
125
  let getData = async() => {
118
126
 
119
127
  //check
120
- if (isarr(_cache)) {
128
+ if (useCache &amp;&amp; isarr(_cache)) {
121
129
  return cloneDeep(_cache) //與外部使用數據脫勾
122
130
  }
123
131
 
@@ -137,10 +145,11 @@ function WOrmLmdb(opt = {}) {
137
145
  ltdt.push(dt)
138
146
  }
139
147
 
140
- //update
141
- _cache = ltdt
142
-
143
- return cloneDeep(ltdt) //與外部使用數據脫勾
148
+ if (useCache) {
149
+ _cache = ltdt
150
+ return cloneDeep(ltdt) //與外部使用數據脫勾
151
+ }
152
+ return ltdt
144
153
  }
145
154
 
146
155
  //getValue
@@ -364,8 +373,11 @@ function WOrmLmdb(opt = {}) {
364
373
  //查找資料表內v.id
365
374
  let vv = await getValue(v.id) //不會有catch
366
375
 
376
+ //existed
377
+ let existed = iseobj(vv)
378
+
367
379
  //check
368
- if (iseobj(vv)) {
380
+ if (existed) {
369
381
  //已存在v.id
370
382
  if (isEqual(v, vv)) {
371
383
  //內容相同不更新
@@ -379,6 +391,9 @@ function WOrmLmdb(opt = {}) {
379
391
  rest = { update: true }
380
392
  }
381
393
  }
394
+ else {
395
+ //內容不存在
396
+ }
382
397
 
383
398
  //rest
384
399
  if (iseobj(rest)) {
@@ -395,9 +410,13 @@ function WOrmLmdb(opt = {}) {
395
410
  ok: 1,
396
411
  }
397
412
  }
413
+ //rest.n === 0:
414
+ // 內容相同不更新, 不須update
415
+ // 內容不存在, 若autoInsert則須insert
398
416
 
399
417
  //autoInsert
400
- if (autoInsert &amp;&amp; rest.n === 0) {
418
+ if (autoInsert &amp;&amp; rest.n === 0 &amp;&amp; !existed) {
419
+ // console.log('insert(v)', v)
401
420
  rest = await insert(v)
402
421
  }
403
422
 
@@ -689,7 +708,7 @@ export default WOrmLmdb
689
708
  <br class="clear">
690
709
 
691
710
  <footer>
692
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Thu May 14 2026 16:50:25 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
711
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri May 15 2026 13:14:13 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
693
712
  </footer>
694
713
 
695
714
  <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 Thu May 14 2026 16:50:25 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 Fri May 15 2026 13:14:13 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
@@ -45,6 +45,14 @@ let rsm = [
45
45
  },
46
46
  ]
47
47
 
48
+ let rsa = [
49
+ {
50
+ id: 'id-rosemary',
51
+ name: 'rosemary',
52
+ value: 654.321,
53
+ },
54
+ ]
55
+
48
56
  async function test() {
49
57
 
50
58
  //wo
@@ -108,6 +116,15 @@ async function test() {
108
116
  // let sr = await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
109
117
  // console.log('selectReg', sr)
110
118
 
119
+ //save
120
+ await wo.save(rsa, { autoInsert: true })
121
+ .then(function(msg) {
122
+ console.log('save then', msg)
123
+ })
124
+ .catch(function(msg) {
125
+ console.log('save catch', msg)
126
+ })
127
+
111
128
  //del
112
129
  let d = ss.filter(function(v) {
113
130
  return v.name === 'kettle'
@@ -162,6 +179,8 @@ test()
162
179
  // value: 123.456
163
180
  // }
164
181
  // ]
182
+ // change save
183
+ // save then [ { n: 1, nModified: 1, ok: 1 } ]
165
184
  // change del
166
185
  // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
167
186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w-orm-lmdb",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "dist/w-orm-lmdb.umd.js",
5
5
  "dependencies": {
6
6
  "lodash-es": "^4.18.1",
package/src/WOrmLmdb.mjs CHANGED
@@ -12,6 +12,7 @@ import isestr from 'wsemi/src/isestr.mjs'
12
12
  import isarr from 'wsemi/src/isarr.mjs'
13
13
  import isearr from 'wsemi/src/isearr.mjs'
14
14
  import iseobj from 'wsemi/src/iseobj.mjs'
15
+ import isbol from 'wsemi/src/isbol.mjs'
15
16
  import haskey from 'wsemi/src/haskey.mjs'
16
17
  import evem from 'wsemi/src/evem.mjs'
17
18
  import genIDSeq from 'wsemi/src/genIDSeq.mjs'
@@ -27,6 +28,7 @@ import waitFun from 'wsemi/src/waitFun.mjs'
27
28
  * @param {String} [opt.url='_db'] 輸入資料庫用資料夾字串,預設'_db'
28
29
  * @param {String} [opt.db='worm'] 輸入使用資料庫名稱字串,預設'worm'
29
30
  * @param {String} [opt.cl='test'] 輸入使用資料表名稱字串,預設'test'
31
+ * @param {Boolean} [opt.useCache=false] 輸入是否使用select快取,適用於單程序操作,預設false
30
32
  * @returns {Object} 回傳操作資料庫物件,各事件功能詳見說明
31
33
  */
32
34
  function WOrmLmdb(opt = {}) {
@@ -52,6 +54,12 @@ function WOrmLmdb(opt = {}) {
52
54
  cl = 'test'
53
55
  }
54
56
 
57
+ //useCache
58
+ let useCache = get(opt, 'useCache')
59
+ if (!isbol(useCache)) {
60
+ useCache = false
61
+ }
62
+
55
63
  //storage
56
64
  let storage = `${url}/${db}/${cl}`
57
65
  // console.log('storage',storage)
@@ -70,7 +78,7 @@ function WOrmLmdb(opt = {}) {
70
78
  let getData = async() => {
71
79
 
72
80
  //check
73
- if (isarr(_cache)) {
81
+ if (useCache && isarr(_cache)) {
74
82
  return cloneDeep(_cache) //與外部使用數據脫勾
75
83
  }
76
84
 
@@ -90,10 +98,11 @@ function WOrmLmdb(opt = {}) {
90
98
  ltdt.push(dt)
91
99
  }
92
100
 
93
- //update
94
- _cache = ltdt
95
-
96
- return cloneDeep(ltdt) //與外部使用數據脫勾
101
+ if (useCache) {
102
+ _cache = ltdt
103
+ return cloneDeep(ltdt) //與外部使用數據脫勾
104
+ }
105
+ return ltdt
97
106
  }
98
107
 
99
108
  //getValue
@@ -317,8 +326,11 @@ function WOrmLmdb(opt = {}) {
317
326
  //查找資料表內v.id
318
327
  let vv = await getValue(v.id) //不會有catch
319
328
 
329
+ //existed
330
+ let existed = iseobj(vv)
331
+
320
332
  //check
321
- if (iseobj(vv)) {
333
+ if (existed) {
322
334
  //已存在v.id
323
335
  if (isEqual(v, vv)) {
324
336
  //內容相同不更新
@@ -332,6 +344,9 @@ function WOrmLmdb(opt = {}) {
332
344
  rest = { update: true }
333
345
  }
334
346
  }
347
+ else {
348
+ //內容不存在
349
+ }
335
350
 
336
351
  //rest
337
352
  if (iseobj(rest)) {
@@ -348,9 +363,13 @@ function WOrmLmdb(opt = {}) {
348
363
  ok: 1,
349
364
  }
350
365
  }
366
+ //rest.n === 0:
367
+ // 內容相同不更新, 不須update
368
+ // 內容不存在, 若autoInsert則須insert
351
369
 
352
370
  //autoInsert
353
- if (autoInsert && rest.n === 0) {
371
+ if (autoInsert && rest.n === 0 && !existed) {
372
+ // console.log('insert(v)', v)
354
373
  rest = await insert(v)
355
374
  }
356
375