w-orm-lowdb 1.0.13 → 1.0.15
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/README.md +121 -15
- package/dist/w-orm-lowdb.umd.js +2 -2
- package/dist/w-orm-lowdb.umd.js.map +1 -1
- package/docs/WOrmLowdb.html +628 -27
- package/docs/WOrmLowdb.mjs.html +1068 -779
- package/docs/index.html +2 -2
- package/g-basic.mjs +203 -185
- package/package.json +3 -3
- package/src/WOrmLowdb.mjs +1066 -777
- package/test/lib/procConcurrency.mjs +53 -0
- package/test/unit-autogenpk.test.mjs +205 -0
- package/test/{basic.test.mjs → unit-basic.test.mjs} +51 -54
- package/test/{cache.test.mjs → unit-cache.test.mjs} +2 -2
- package/test/unit-concurrency.test.mjs +140 -0
- package/test/unit-del.test.mjs +140 -0
- package/test/unit-delall.test.mjs +153 -0
- package/test/unit-event.test.mjs +252 -0
- package/test/unit-insert.test.mjs +120 -0
- package/test/unit-insertbulk.test.mjs +188 -0
- package/test/unit-returnlist.test.mjs +159 -0
- package/test/unit-save.test.mjs +199 -0
- package/test/unit-selectbypk.test.mjs +121 -0
- package/toolg/gDistRollup.mjs +3 -3
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="WOrmLowdb.html">WOrmLowdb</a><ul class='methods'><li data-type='method'><a href="WOrmLowdb.html#.delAllCore">delAllCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.delCore">delCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.insertCore">insertCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.saveCore">saveCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.selectCore">selectCore</a></li></ul></li></ul>
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WOrmLowdb.html">WOrmLowdb</a><ul class='methods'><li data-type='method'><a href="WOrmLowdb.html#.delAllCore">delAllCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.delCore">delCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.insertBulkCore">insertBulkCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.insertCore">insertCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.saveCore">saveCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.selectByPkCore">selectByPkCore</a></li><li data-type='method'><a href="WOrmLowdb.html#.selectCore">selectCore</a></li><li data-type='method'><a href="WOrmLowdb.html#~serialize">serialize</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
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Tue Aug 18 2026 12:13:49 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
|
@@ -1,185 +1,203 @@
|
|
|
1
|
-
import WOrm from './src/WOrmLowdb.mjs'
|
|
2
|
-
//import WOrm from './dist/w-orm-lowdb.umd.js'
|
|
3
|
-
// import w from 'wsemi'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// w.fsDeleteFile('./db.json')
|
|
7
|
-
|
|
8
|
-
let opt = {
|
|
9
|
-
url: './db.json',
|
|
10
|
-
db: 'worm',
|
|
11
|
-
cl: 'users',
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let rs = [
|
|
15
|
-
{
|
|
16
|
-
id: 'id-peter',
|
|
17
|
-
name: 'peter',
|
|
18
|
-
value: 123,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
id: 'id-rosemary',
|
|
22
|
-
name: 'rosemary',
|
|
23
|
-
value: 123.456,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
id: '',
|
|
27
|
-
name: 'kettle',
|
|
28
|
-
value: 456,
|
|
29
|
-
},
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
let rsm = [
|
|
33
|
-
{
|
|
34
|
-
id: 'id-peter',
|
|
35
|
-
name: 'peter(modify)'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: 'id-rosemary',
|
|
39
|
-
name: 'rosemary(modify)'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
id: '',
|
|
43
|
-
name: 'kettle(modify)'
|
|
44
|
-
},
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
let rsa = [
|
|
48
|
-
{
|
|
49
|
-
id: 'id-rosemary',
|
|
50
|
-
name: 'rosemary',
|
|
51
|
-
value: 654.321,
|
|
52
|
-
},
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
async function test() {
|
|
56
|
-
|
|
57
|
-
//wo
|
|
58
|
-
let wo = WOrm(opt)
|
|
59
|
-
|
|
60
|
-
//on
|
|
61
|
-
wo.on('change', function(mode, data, res) {
|
|
62
|
-
console.log('change', mode)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
console.log('delAll
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.
|
|
80
|
-
console.log('insert
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
.
|
|
89
|
-
console.log('
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
.
|
|
119
|
-
console.log('save
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// select by
|
|
160
|
-
// select
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
1
|
+
import WOrm from './src/WOrmLowdb.mjs'
|
|
2
|
+
//import WOrm from './dist/w-orm-lowdb.umd.js'
|
|
3
|
+
// import w from 'wsemi'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// w.fsDeleteFile('./db.json')
|
|
7
|
+
|
|
8
|
+
let opt = {
|
|
9
|
+
url: './db.json',
|
|
10
|
+
db: 'worm',
|
|
11
|
+
cl: 'users',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let rs = [
|
|
15
|
+
{
|
|
16
|
+
id: 'id-peter',
|
|
17
|
+
name: 'peter',
|
|
18
|
+
value: 123,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 'id-rosemary',
|
|
22
|
+
name: 'rosemary',
|
|
23
|
+
value: 123.456,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: '',
|
|
27
|
+
name: 'kettle',
|
|
28
|
+
value: 456,
|
|
29
|
+
},
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
let rsm = [
|
|
33
|
+
{
|
|
34
|
+
id: 'id-peter',
|
|
35
|
+
name: 'peter(modify)'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'id-rosemary',
|
|
39
|
+
name: 'rosemary(modify)'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: '',
|
|
43
|
+
name: 'kettle(modify)'
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
let rsa = [
|
|
48
|
+
{
|
|
49
|
+
id: 'id-rosemary',
|
|
50
|
+
name: 'rosemary',
|
|
51
|
+
value: 654.321,
|
|
52
|
+
},
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
async function test() {
|
|
56
|
+
|
|
57
|
+
//wo
|
|
58
|
+
let wo = WOrm(opt)
|
|
59
|
+
|
|
60
|
+
//on
|
|
61
|
+
wo.on('change', function(mode, data, res) {
|
|
62
|
+
console.log('change', mode)
|
|
63
|
+
})
|
|
64
|
+
wo.on('error', function(mode, data, err) {
|
|
65
|
+
console.log('error', mode, err)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
//delAll
|
|
69
|
+
await wo.delAll()
|
|
70
|
+
.then(function(msg) {
|
|
71
|
+
console.log('delAll then', msg)
|
|
72
|
+
})
|
|
73
|
+
.catch(function(msg) {
|
|
74
|
+
console.log('delAll catch', msg)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
//insert
|
|
78
|
+
await wo.insert(rs)
|
|
79
|
+
.then(function(msg) {
|
|
80
|
+
console.log('insert then', msg)
|
|
81
|
+
})
|
|
82
|
+
.catch(function(msg) {
|
|
83
|
+
console.log('insert catch', msg)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
//insert by returnList, 回傳與輸入等長保序之逐筆結果, nInserted為1即該筆為新增
|
|
87
|
+
await wo.insert([{ id: 'id-peter' }, { id: 'id-new' }], { returnList: true })
|
|
88
|
+
.then(function(msg) {
|
|
89
|
+
console.log('insert(returnList) then', msg)
|
|
90
|
+
})
|
|
91
|
+
.catch(function(msg) {
|
|
92
|
+
console.log('insert(returnList) catch', msg)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
//insertBulk, 全有全無, 任一筆主鍵已存在即整批reject且不寫入任何一筆
|
|
96
|
+
await wo.insertBulk([{ id: 'id-bulk1' }, { id: 'id-bulk2' }])
|
|
97
|
+
.then(function(msg) {
|
|
98
|
+
console.log('insertBulk then', msg)
|
|
99
|
+
})
|
|
100
|
+
.catch(function(msg) {
|
|
101
|
+
console.log('insertBulk catch', msg.toString())
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
//insertBulk by existed id
|
|
105
|
+
await wo.insertBulk([{ id: 'id-bulk3' }, { id: 'id-peter' }])
|
|
106
|
+
.then(function(msg) {
|
|
107
|
+
console.log('insertBulk(existed) then', msg)
|
|
108
|
+
})
|
|
109
|
+
.catch(function(msg) {
|
|
110
|
+
console.log('insertBulk(existed) catch', msg.toString())
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
//save
|
|
114
|
+
await wo.save(rsm, { autoInsert: false })
|
|
115
|
+
.then(function(msg) {
|
|
116
|
+
console.log('save then', msg)
|
|
117
|
+
})
|
|
118
|
+
.catch(function(msg) {
|
|
119
|
+
console.log('save catch', msg)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
//selectByPk
|
|
123
|
+
let sp = await wo.selectByPk('id-rosemary')
|
|
124
|
+
console.log('selectByPk', sp)
|
|
125
|
+
|
|
126
|
+
//selectByPk by non-existed id
|
|
127
|
+
let spn = await wo.selectByPk('id-non-existed')
|
|
128
|
+
console.log('selectByPk(non-existed)', spn)
|
|
129
|
+
|
|
130
|
+
//del by id-new, id-bulk1, id-bulk2
|
|
131
|
+
await wo.del([{ id: 'id-new' }, { id: 'id-bulk1' }, { id: 'id-bulk2' }])
|
|
132
|
+
.then(function(msg) {
|
|
133
|
+
console.log('del(clean) then', msg)
|
|
134
|
+
})
|
|
135
|
+
.catch(function(msg) {
|
|
136
|
+
console.log('del(clean) catch', msg)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
//select all
|
|
140
|
+
let ss = await wo.select()
|
|
141
|
+
console.log('select all', ss)
|
|
142
|
+
|
|
143
|
+
//select
|
|
144
|
+
let so = await wo.select({ id: 'id-rosemary' })
|
|
145
|
+
console.log('select', so)
|
|
146
|
+
|
|
147
|
+
//select by $and, $gt, $lt
|
|
148
|
+
let spa = await wo.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
|
|
149
|
+
console.log('select by $and, $gt, $lt', spa)
|
|
150
|
+
|
|
151
|
+
//select by $or, $gte, $lte
|
|
152
|
+
let spb = await wo.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
|
|
153
|
+
console.log('select by $or, $gte, $lte', spb)
|
|
154
|
+
|
|
155
|
+
//select by $or, $and, $ne, $in, $nin
|
|
156
|
+
let spc = await wo.select({ '$or': [{ '$and': [{ value: { '$ne': 123 } }, { value: { '$in': [123, 321, 123.456, 456] } }, { value: { '$nin': [456, 654] } }] }, { '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 400 } }] }] })
|
|
157
|
+
console.log('select by $or, $and, $ne, $in, $nin', spc)
|
|
158
|
+
|
|
159
|
+
// //select by regex //mingo不支援regex
|
|
160
|
+
// let sr = await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
|
|
161
|
+
// console.log('selectReg', sr)
|
|
162
|
+
|
|
163
|
+
//save
|
|
164
|
+
await wo.save(rsa, { autoInsert: true })
|
|
165
|
+
.then(function(msg) {
|
|
166
|
+
console.log('save then', msg)
|
|
167
|
+
})
|
|
168
|
+
.catch(function(msg) {
|
|
169
|
+
console.log('save catch', msg)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
//del
|
|
173
|
+
let d = ss.filter(function(v) {
|
|
174
|
+
return v.name === 'kettle'
|
|
175
|
+
})
|
|
176
|
+
await wo.del(d)
|
|
177
|
+
.then(function(msg) {
|
|
178
|
+
console.log('del then', msg)
|
|
179
|
+
})
|
|
180
|
+
.catch(function(msg) {
|
|
181
|
+
console.log('del catch', msg)
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
//del by invalid id, 未帶有效主鍵者為該筆ok為0並附err, 整批仍resolve
|
|
185
|
+
await wo.del([{ name: 'no-id' }])
|
|
186
|
+
.then(function(msg) {
|
|
187
|
+
console.log('del(invalid id) then', msg)
|
|
188
|
+
})
|
|
189
|
+
.catch(function(msg) {
|
|
190
|
+
console.log('del(invalid id) catch', msg)
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
//delAll by find
|
|
194
|
+
await wo.delAll({ value: { '$gte': 600 } })
|
|
195
|
+
.then(function(msg) {
|
|
196
|
+
console.log('delAll(find) then', msg)
|
|
197
|
+
})
|
|
198
|
+
.catch(function(msg) {
|
|
199
|
+
console.log('delAll(find) catch', msg)
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
test()
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w-orm-lowdb",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"main": "dist/w-orm-lowdb.umd.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"lowdb": "^7.0.1",
|
|
7
|
-
"mingo": "^7.2.
|
|
8
|
-
"wsemi": "^1.8.
|
|
7
|
+
"mingo": "^7.2.4",
|
|
8
|
+
"wsemi": "^1.8.73"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"w-package-tools": "^1.1.12"
|