w-orm-lowdb 1.0.13 → 1.0.14

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/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 Sat Aug 08 2026 14:30:09 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 20:57:08 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
- //delAll
66
- await wo.delAll()
67
- .then(function(msg) {
68
- console.log('delAll then', msg)
69
- })
70
- .catch(function(msg) {
71
- console.log('delAll catch', msg)
72
- })
73
-
74
- //insert
75
- await wo.insert(rs)
76
- .then(function(msg) {
77
- console.log('insert then', msg)
78
- })
79
- .catch(function(msg) {
80
- console.log('insert catch', msg)
81
- })
82
-
83
- //save
84
- await wo.save(rsm, { autoInsert: false })
85
- .then(function(msg) {
86
- console.log('save then', msg)
87
- })
88
- .catch(function(msg) {
89
- console.log('save catch', msg)
90
- })
91
-
92
- //select all
93
- let ss = await wo.select()
94
- console.log('select all', ss)
95
-
96
- //select
97
- let so = await wo.select({ id: 'id-rosemary' })
98
- console.log('select', so)
99
-
100
- //select by $and, $gt, $lt
101
- let spa = await wo.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
102
- console.log('select by $and, $gt, $lt', spa)
103
-
104
- //select by $or, $gte, $lte
105
- let spb = await wo.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
106
- console.log('select by $or, $gte, $lte', spb)
107
-
108
- //select by $or, $and, $ne, $in, $nin
109
- 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 } }] }] })
110
- console.log('select by $or, $and, $ne, $in, $nin', spc)
111
-
112
- // //select by regex //mingo不支援regex
113
- // let sr = await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
114
- // console.log('selectReg', sr)
115
-
116
- //save
117
- await wo.save(rsa, { autoInsert: true })
118
- .then(function(msg) {
119
- console.log('save then', msg)
120
- })
121
- .catch(function(msg) {
122
- console.log('save catch', msg)
123
- })
124
-
125
- //del
126
- let d = ss.filter(function(v) {
127
- return v.name === 'kettle'
128
- })
129
- await wo.del(d)
130
- .then(function(msg) {
131
- console.log('del then', msg)
132
- })
133
- .catch(function(msg) {
134
- console.log('del catch', msg)
135
- })
136
-
137
- }
138
- test()
139
- // change delAll
140
- // delAll then { n: 2, nDeleted: 2, ok: 1 }
141
- // change insert
142
- // insert then { n: 3, nInserted: 3, ok: 1 }
143
- // change save
144
- // save then [
145
- // { n: 1, nModified: 1, ok: 1 },
146
- // { n: 1, nModified: 1, ok: 1 },
147
- // { n: 0, nModified: 0, ok: 1 }
148
- // ]
149
- // select all [
150
- // { id: 'id-peter', name: 'peter(modify)', value: 123 },
151
- // { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 },
152
- // {
153
- // id: {random id},
154
- // name: 'kettle',
155
- // value: 456
156
- // }
157
- // ]
158
- // select [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
159
- // select by $and, $gt, $lt [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
160
- // select by $or, $gte, $lte [
161
- // {
162
- // id: {random id},
163
- // name: 'kettle',
164
- // value: 456
165
- // }
166
- // ]
167
- // select by $or, $and, $ne, $in, $nin [
168
- // {
169
- // id: 'id-rosemary',
170
- // name: 'rosemary(modify)',
171
- // value: 123.456
172
- // },
173
- // {
174
- // id: {random id},
175
- // name: 'kettle',
176
- // value: 456
177
- // }
178
- // ]
179
- // change save
180
- // save then [ { n: 1, nModified: 1, ok: 1 } ]
181
- // change del
182
- // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
183
-
184
-
185
- //node g-basic.mjs
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,10 +1,10 @@
1
1
  {
2
2
  "name": "w-orm-lowdb",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "main": "dist/w-orm-lowdb.umd.js",
5
5
  "dependencies": {
6
6
  "lowdb": "^7.0.1",
7
- "mingo": "^7.2.1",
7
+ "mingo": "^7.2.4",
8
8
  "wsemi": "^1.8.70"
9
9
  },
10
10
  "devDependencies": {