w-orm-lowdb 1.0.8 → 1.0.9
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/dist/w-orm-lowdb.umd.js +2 -2
- package/dist/w-orm-lowdb.umd.js.map +1 -1
- package/docs/WOrmLowdb.html +47 -7
- package/docs/WOrmLowdb.mjs.html +17 -5
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/WOrmLowdb.mjs +16 -4
- package/test/basic.test.mjs +417 -380
- package/test/cache.test.mjs +172 -0
package/docs/WOrmLowdb.html
CHANGED
|
@@ -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="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#
|
|
83
|
+
<a href="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#line40">line 40</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
|
+
<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="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#
|
|
472
|
+
<a href="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#line635">line 635</a>
|
|
433
473
|
</li></ul></dd>
|
|
434
474
|
|
|
435
475
|
|
|
@@ -607,7 +647,7 @@
|
|
|
607
647
|
|
|
608
648
|
<dt class="tag-source">Source:</dt>
|
|
609
649
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
610
|
-
<a href="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#
|
|
650
|
+
<a href="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#line482">line 482</a>
|
|
611
651
|
</li></ul></dd>
|
|
612
652
|
|
|
613
653
|
|
|
@@ -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="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#
|
|
811
|
+
<a href="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#line185">line 185</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="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#
|
|
972
|
+
<a href="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#line314">line 314</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="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#
|
|
1259
|
+
<a href="WOrmLowdb.mjs.html">WOrmLowdb.mjs</a>, <a href="WOrmLowdb.mjs.html#line128">line 128</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
|
|
1436
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri May 15 2026 13:15:06 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1397
1437
|
</footer>
|
|
1398
1438
|
|
|
1399
1439
|
<script>prettyPrint();</script>
|
package/docs/WOrmLowdb.mjs.html
CHANGED
|
@@ -60,6 +60,7 @@ import cloneDeep from 'lodash-es/cloneDeep.js'
|
|
|
60
60
|
import genID from 'wsemi/src/genID.mjs'
|
|
61
61
|
import pmSeries from 'wsemi/src/pmSeries.mjs'
|
|
62
62
|
import isarr from 'wsemi/src/isarr.mjs'
|
|
63
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
63
64
|
import isestr from 'wsemi/src/isestr.mjs'
|
|
64
65
|
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
65
66
|
import isearr from 'wsemi/src/isearr.mjs'
|
|
@@ -80,6 +81,7 @@ let kpGlock = {}
|
|
|
80
81
|
* @param {String} [opt.url='./db.json'] 輸入資料庫位置字串,預設'./db.json'
|
|
81
82
|
* @param {String} [opt.db='worm'] 輸入使用資料庫名稱字串,預設'worm'
|
|
82
83
|
* @param {String} [opt.cl='test'] 輸入使用資料表名稱字串,預設'test'
|
|
84
|
+
* @param {Boolean} [opt.useCache=false] 輸入是否使用select快取,適用於單程序操作,預設false
|
|
83
85
|
* @returns {Object} 回傳操作資料庫物件,各事件功能詳見說明
|
|
84
86
|
*/
|
|
85
87
|
function WOrmLowdb(opt = {}) {
|
|
@@ -105,6 +107,12 @@ function WOrmLowdb(opt = {}) {
|
|
|
105
107
|
cl = 'test'
|
|
106
108
|
}
|
|
107
109
|
|
|
110
|
+
//useCache
|
|
111
|
+
let useCache = get(opt, 'useCache')
|
|
112
|
+
if (!isbol(useCache)) {
|
|
113
|
+
useCache = false
|
|
114
|
+
}
|
|
115
|
+
|
|
108
116
|
//key
|
|
109
117
|
let key = `${db}:${cl}`
|
|
110
118
|
|
|
@@ -135,7 +143,7 @@ function WOrmLowdb(opt = {}) {
|
|
|
135
143
|
let getData = async() => {
|
|
136
144
|
|
|
137
145
|
//check
|
|
138
|
-
if (isarr(_cache)) {
|
|
146
|
+
if (useCache && isarr(_cache)) {
|
|
139
147
|
return cloneDeep(_cache) //與外部使用數據脫勾
|
|
140
148
|
}
|
|
141
149
|
|
|
@@ -147,10 +155,14 @@ function WOrmLowdb(opt = {}) {
|
|
|
147
155
|
lowdb.data[key] = []
|
|
148
156
|
}
|
|
149
157
|
|
|
150
|
-
//
|
|
151
|
-
|
|
158
|
+
//ltdt
|
|
159
|
+
let ltdt = cloneDeep(lowdb.data[key]) //數據為lowdb內部的記憶體狀態本體, 須cloneDeep與外部使用數據脫勾
|
|
152
160
|
|
|
153
|
-
|
|
161
|
+
if (useCache) {
|
|
162
|
+
_cache = ltdt
|
|
163
|
+
return cloneDeep(ltdt) //與外部使用數據脫勾
|
|
164
|
+
}
|
|
165
|
+
return ltdt
|
|
154
166
|
}
|
|
155
167
|
|
|
156
168
|
/**
|
|
@@ -824,7 +836,7 @@ export default WOrmLowdb
|
|
|
824
836
|
<br class="clear">
|
|
825
837
|
|
|
826
838
|
<footer>
|
|
827
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
839
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri May 15 2026 13:15:06 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
828
840
|
</footer>
|
|
829
841
|
|
|
830
842
|
<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
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri May 15 2026 13:15:06 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/package.json
CHANGED
package/src/WOrmLowdb.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import cloneDeep from 'lodash-es/cloneDeep.js'
|
|
|
13
13
|
import genID from 'wsemi/src/genID.mjs'
|
|
14
14
|
import pmSeries from 'wsemi/src/pmSeries.mjs'
|
|
15
15
|
import isarr from 'wsemi/src/isarr.mjs'
|
|
16
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
16
17
|
import isestr from 'wsemi/src/isestr.mjs'
|
|
17
18
|
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
18
19
|
import isearr from 'wsemi/src/isearr.mjs'
|
|
@@ -33,6 +34,7 @@ let kpGlock = {}
|
|
|
33
34
|
* @param {String} [opt.url='./db.json'] 輸入資料庫位置字串,預設'./db.json'
|
|
34
35
|
* @param {String} [opt.db='worm'] 輸入使用資料庫名稱字串,預設'worm'
|
|
35
36
|
* @param {String} [opt.cl='test'] 輸入使用資料表名稱字串,預設'test'
|
|
37
|
+
* @param {Boolean} [opt.useCache=false] 輸入是否使用select快取,適用於單程序操作,預設false
|
|
36
38
|
* @returns {Object} 回傳操作資料庫物件,各事件功能詳見說明
|
|
37
39
|
*/
|
|
38
40
|
function WOrmLowdb(opt = {}) {
|
|
@@ -58,6 +60,12 @@ function WOrmLowdb(opt = {}) {
|
|
|
58
60
|
cl = 'test'
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
//useCache
|
|
64
|
+
let useCache = get(opt, 'useCache')
|
|
65
|
+
if (!isbol(useCache)) {
|
|
66
|
+
useCache = false
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
//key
|
|
62
70
|
let key = `${db}:${cl}`
|
|
63
71
|
|
|
@@ -88,7 +96,7 @@ function WOrmLowdb(opt = {}) {
|
|
|
88
96
|
let getData = async() => {
|
|
89
97
|
|
|
90
98
|
//check
|
|
91
|
-
if (isarr(_cache)) {
|
|
99
|
+
if (useCache && isarr(_cache)) {
|
|
92
100
|
return cloneDeep(_cache) //與外部使用數據脫勾
|
|
93
101
|
}
|
|
94
102
|
|
|
@@ -100,10 +108,14 @@ function WOrmLowdb(opt = {}) {
|
|
|
100
108
|
lowdb.data[key] = []
|
|
101
109
|
}
|
|
102
110
|
|
|
103
|
-
//
|
|
104
|
-
|
|
111
|
+
//ltdt
|
|
112
|
+
let ltdt = cloneDeep(lowdb.data[key]) //數據為lowdb內部的記憶體狀態本體, 須cloneDeep與外部使用數據脫勾
|
|
105
113
|
|
|
106
|
-
|
|
114
|
+
if (useCache) {
|
|
115
|
+
_cache = ltdt
|
|
116
|
+
return cloneDeep(ltdt) //與外部使用數據脫勾
|
|
117
|
+
}
|
|
118
|
+
return ltdt
|
|
107
119
|
}
|
|
108
120
|
|
|
109
121
|
/**
|