w-orm-lmdb 1.0.5 → 1.0.7

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.
@@ -4,424 +4,418 @@ import w from 'wsemi'
4
4
  import WOrm from '../src/WOrmLmdb.mjs'
5
5
 
6
6
 
7
- function isWindows() {
8
- return process.platform === 'win32'
9
- }
10
-
11
- if (isWindows()) {
12
- describe('basic', function() {
13
- let rt = null
14
- let vans = {}
15
- let vget = {}
16
-
17
- before(async function () {
18
-
19
- w.fsDeleteFolder('./_db')
20
-
21
- let opt = {
22
- url: './_db',
23
- db: 'worm',
24
- cl: 'users',
25
- }
26
-
27
- let rs = [
28
- {
29
- id: 'id-peter',
30
- name: 'peter',
31
- value: 123,
32
- },
33
- {
34
- id: 'id-rosemary',
35
- name: 'rosemary',
36
- value: 123.456,
37
- },
38
- {
39
- id: '',
40
- name: 'kettle',
41
- value: 456,
42
- },
43
- ]
44
-
45
- let rsm = [
46
- {
47
- id: 'id-peter',
48
- name: 'peter(modify)'
49
- },
50
- {
51
- id: 'id-rosemary',
52
- name: 'rosemary(modify)'
53
- },
54
- {
55
- id: '',
56
- name: 'kettle(modify)'
57
- },
58
- ]
59
-
60
- let rsa = [
61
- {
62
- id: 'id-rosemary',
63
- name: 'rosemary',
64
- value: 654.321,
65
- },
66
- ]
67
-
68
- //wo
69
- let wo = WOrm(opt)
70
-
71
- //on
72
- wo.on('change', function(mode, data, res) {
73
- // console.log('change', mode)
74
- })
7
+ describe('basic', function() {
8
+ let rt = null
9
+ let vans = {}
10
+ let vget = {}
75
11
 
76
- //delAll
77
- rt = null
78
- // vans[1] = {
79
- // nDeleted: 0,
80
- // ok: 1,
81
- // }
82
- await wo.delAll()
83
- .then(function(msg) {
84
- // console.log('delAll then', msg)
85
- //考慮可能有不同初始測試數據
86
- // delAll then { n: 2, nDeleted: 2, ok: 1 }
87
- // delAll then { n: 3, nDeleted: 2, ok: 1 }
88
- //僅針對nDeleted與ok欄位比對
89
- rt = {
90
- nDeleted: msg.nDeleted,
91
- ok: msg.ok,
92
- }
93
- })
94
- .catch(function(msg) {
95
- // console.log('delAll catch', msg)
96
- rt = msg.toString()
97
- })
98
- vget[1] = rt
99
-
100
- //insert
101
- rt = null
102
- // vans[2] = { n: 3, nInserted: 3, ok: 1 }
103
- await wo.insert(rs)
104
- .then(function(msg) {
105
- // console.log('insert then', msg)
106
- // insert then { n: 3, nInserted: 3, ok: 1 }
107
- rt = msg
108
- })
109
- .catch(function(msg) {
110
- // console.log('insert catch', msg)
111
- rt = msg.toString()
112
- })
113
- vget[2] = rt
114
-
115
- //save
116
- rt = null
117
- // vans[3] = [
118
- // { n: 1, nModified: 1, ok: 1 },
119
- // { n: 1, nModified: 1, ok: 1 },
120
- // { n: 0, nModified: 0, ok: 1 }
121
- // ]
122
- await wo.save(rsm, { autoInsert: false })
123
- .then(function(msg) {
124
- // console.log('save then', msg)
125
- // save then [
126
- // { n: 1, nModified: 1, ok: 1 },
127
- // { n: 1, nModified: 1, ok: 1 },
128
- // { n: 0, nModified: 0, ok: 1 }
129
- // ]
130
- rt = msg
131
- })
132
- .catch(function(msg) {
133
- // console.log('save catch', msg)
134
- rt = msg.toString()
135
- })
136
- vget[3] = rt
137
-
138
- //select all
139
- rt = null
140
- // vans[4] = [
141
- // {
142
- // // id: {random id},
143
- // name: 'kettle',
144
- // value: 456
145
- // },
146
- // { id: 'id-peter', name: 'peter(modify)', value: 123 },
147
- // { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 },
148
- // ]
149
- await wo.select()
150
- .then(function(msg) {
151
- // console.log('select all then', msg)
152
- msg = _.sortBy(msg, 'name')
153
- // select all [
154
- // {
155
- // id: {random id},
156
- // name: 'kettle',
157
- // value: 456
158
- // },
159
- // { id: 'id-peter', name: 'peter(modify)', value: 123 },
160
- // { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
161
- // ]
162
- rt = [
163
- {
164
- name: msg[0].name,
165
- value: msg[0].value,
166
- },
167
- msg[1],
168
- msg[2],
169
- ]
170
- })
171
- .catch(function(msg) {
172
- // console.log('select all catch', msg)
173
- rt = msg.toString()
174
- })
175
- vget[4] = rt
176
-
177
- //select
178
- rt = null
179
- // vans[5] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
180
- await wo.select({ id: 'id-rosemary' })
181
- .then(function(msg) {
182
- // console.log('select then', msg)
183
- // select [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
184
- rt = msg
185
- })
186
- .catch(function(msg) {
187
- // console.log('select catch', msg)
188
- rt = msg.toString()
189
- })
190
- vget[5] = rt
191
-
192
- //select by $and, $gt, $lt
193
- rt = null
194
- // vans[6] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
195
- await wo.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
196
- .then(function(msg) {
197
- // console.log('select by $and, $gt, $lt then', msg)
198
- // select by $and, $gt, $lt [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
199
- rt = msg
200
- })
201
- .catch(function(msg) {
202
- // console.log('select by $and, $gt, $lt catch', msg)
203
- rt = msg.toString()
204
- })
205
- vget[6] = rt
206
-
207
- //select by $or, $gte, $lte
208
- rt = null
209
- // vans[7] = [
210
- // {
211
- // // id: {random id},
212
- // name: 'kettle',
213
- // value: 456
214
- // }
215
- // ]
216
- await wo.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
217
- .then(function(msg) {
218
- // console.log('select by $or, $gte, $lte then', msg)
219
- // select by $or, $gte, $lte [
220
- // {
221
- // id: {random id},
222
- // name: 'kettle',
223
- // value: 456
224
- // }
225
- // ]
226
- rt = [
227
- {
228
- name: msg[0].name,
229
- value: msg[0].value,
230
- },
231
- ]
232
- })
233
- .catch(function(msg) {
234
- // console.log('select by $or, $gte, $lte catch', msg)
235
- rt = msg.toString()
236
- })
237
- vget[7] = rt
238
-
239
- //select by $or, $and, $ne, $in, $nin
240
- rt = null
241
- // vans[8] = [
242
- // {
243
- // id: 'id-rosemary',
244
- // name: 'rosemary(modify)',
245
- // value: 123.456
246
- // },
247
- // {
248
- // // id: {random id},
249
- // name: 'kettle',
250
- // value: 456
251
- // }
252
- // ]
253
- 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 } }] }] })
254
- .then(function(msg) {
255
- // console.log('select by $or, $and, $ne, $in, $nin then', msg)
256
- msg = _.sortBy(msg, 'name')
257
- // select by $or, $and, $ne, $in, $nin [
258
- // {
259
- // id: 'id-rosemary',
260
- // name: 'rosemary(modify)',
261
- // value: 123.456
262
- // },
263
- // {
264
- // id: {random id},
265
- // name: 'kettle',
266
- // value: 456
267
- // }
268
- // ]
269
- rt = [
270
- {
271
- name: msg[0].name,
272
- value: msg[0].value,
273
- },
274
- msg[1],
275
- ]
276
- })
277
- .catch(function(msg) {
278
- // console.log('select by $or, $and, $ne, $in, $nin catch', msg)
279
- rt = msg.toString()
280
- })
281
- vget[8] = rt
282
-
283
- // //select by regex
284
- // rt = null
285
- // vans[9] = [{ id: 'id-peter', name: 'peter(modify)', value: 123 }]
286
- // await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
287
- // .then(function(msg) {
288
- // // console.log('select by regex then', msg)
289
- // // selectReg [ { id: 'id-peter', name: 'peter(modify)', value: 123 } ]
290
- // rt = msg
291
- // })
292
- // .catch(function(msg) {
293
- // // console.log('select by regex catch', msg)
294
- // rt = msg.toString()
295
- // })
296
- // vget[9] = rt
297
-
298
- //save
299
- rt = null
300
- // vans[10] = [ { n: 1, nModified: 1, ok: 1 } ]
301
- await wo.save(rsa, { autoInsert: true })
302
- .then(function(msg) {
303
- // console.log('save then', msg)
304
- // save then [
305
- // { n: 1, nModified: 1, ok: 1 },
306
- // { n: 1, nModified: 1, ok: 1 },
307
- // { n: 0, nModified: 0, ok: 1 }
308
- // ]
309
- rt = msg
310
- })
311
- .catch(function(msg) {
312
- // console.log('save catch', msg)
313
- rt = msg.toString()
314
- })
315
- vget[10] = rt
316
-
317
- //del
318
- rt = null
319
- // vans[11] = [{ n: 1, nDeleted: 1, ok: 1 }]
320
- let ss = await wo.select()
321
- let d = ss.filter(function(v) {
322
- return v.name === 'kettle'
323
- })
324
- await wo.del(d)
325
- .then(function(msg) {
326
- // console.log('del then', msg)
327
- // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
328
- rt = msg
329
- })
330
- .catch(function(msg) {
331
- // console.log('del catch', msg)
332
- rt = msg.toString()
333
- })
334
- vget[11] = rt
12
+ before(async function () {
335
13
 
336
- })
14
+ w.fsDeleteFolder('./_db')
337
15
 
338
- vans[1] = {
339
- nDeleted: 0,
340
- ok: 1,
16
+ let opt = {
17
+ url: './_db',
18
+ db: 'worm',
19
+ cl: 'users',
341
20
  }
342
- it(`should get ${JSON.stringify(vans[1])} for delAll`, async function() {
343
- assert.strict.deepStrictEqual(vget[1], vans[1])
344
- })
345
-
346
- vans[2] = { n: 3, nInserted: 3, ok: 1 }
347
- it(`should get ${JSON.stringify(vans[2])} for insert`, async function() {
348
- assert.strict.deepStrictEqual(vget[2], vans[2])
349
- })
350
21
 
351
- vans[3] = [
352
- { n: 1, nModified: 1, ok: 1 },
353
- { n: 1, nModified: 1, ok: 1 },
354
- { n: 0, nModified: 0, ok: 1 }
355
- ]
356
- it(`should get ${JSON.stringify(vans[3])} for save(autoInsert=false)`, async function() {
357
- assert.strict.deepStrictEqual(vget[3], vans[3])
358
- })
359
-
360
- vans[4] = [
22
+ let rs = [
361
23
  {
362
- // id: {random id},
363
- name: 'kettle',
364
- value: 456
24
+ id: 'id-peter',
25
+ name: 'peter',
26
+ value: 123,
27
+ },
28
+ {
29
+ id: 'id-rosemary',
30
+ name: 'rosemary',
31
+ value: 123.456,
365
32
  },
366
- { id: 'id-peter', name: 'peter(modify)', value: 123 },
367
- { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 },
368
- ]
369
- it(`should get ${JSON.stringify(vans[4])} for select all`, async function() {
370
- assert.strict.deepStrictEqual(vget[4], vans[4])
371
- })
372
-
373
- vans[5] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
374
- it(`should get ${JSON.stringify(vans[5])} for select`, async function() {
375
- assert.strict.deepStrictEqual(vget[5], vans[5])
376
- })
377
-
378
- vans[6] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
379
- it(`should get ${JSON.stringify(vans[6])} for select by $and, $gt, $lt`, async function() {
380
- assert.strict.deepStrictEqual(vget[6], vans[6])
381
- })
382
-
383
- vans[7] = [
384
33
  {
385
- // id: {random id},
34
+ id: '',
386
35
  name: 'kettle',
387
- value: 456
388
- }
36
+ value: 456,
37
+ },
389
38
  ]
390
- it(`should get ${JSON.stringify(vans[7])} for select by $or, $gte, $lte`, async function() {
391
- assert.strict.deepStrictEqual(vget[7], vans[7])
392
- })
393
39
 
394
- vans[8] = [
40
+ let rsm = [
395
41
  {
396
- // id: {random id},
397
- name: 'kettle',
398
- value: 456
42
+ id: 'id-peter',
43
+ name: 'peter(modify)'
399
44
  },
400
45
  {
401
46
  id: 'id-rosemary',
402
- name: 'rosemary(modify)',
403
- value: 123.456
404
- }
47
+ name: 'rosemary(modify)'
48
+ },
49
+ {
50
+ id: '',
51
+ name: 'kettle(modify)'
52
+ },
405
53
  ]
406
- it(`should get ${JSON.stringify(vans[8])} for select by $or, $and, $ne, $in, $nin`, async function() {
407
- assert.strict.deepStrictEqual(vget[8], vans[8])
408
- })
409
54
 
410
- // vans[9] = [{ id: 'id-peter', name: 'peter(modify)', value: 123 }]
411
- // it(`should get ${JSON.stringify(vans[9])} for select by regex`, async function() {
412
- // assert.strict.deepStrictEqual(vget[9], vans[9])
413
- // })
55
+ let rsa = [
56
+ {
57
+ id: 'id-rosemary',
58
+ name: 'rosemary',
59
+ value: 654.321,
60
+ },
61
+ ]
62
+
63
+ //wo
64
+ let wo = WOrm(opt)
414
65
 
415
- vans[10] = [{ n: 1, nModified: 1, ok: 1 }]
416
- it(`should get ${JSON.stringify(vans[10])} for save(autoInsert=true)`, async function() {
417
- assert.strict.deepStrictEqual(vget[10], vans[10])
66
+ //on
67
+ wo.on('change', function(mode, data, res) {
68
+ // console.log('change', mode)
418
69
  })
419
70
 
420
- vans[11] = [{ n: 1, nDeleted: 1, ok: 1 }]
421
- it(`should get ${JSON.stringify(vans[11])} for del`, async function() {
422
- assert.strict.deepStrictEqual(vget[11], vans[11])
71
+ //delAll
72
+ rt = null
73
+ // vans[1] = {
74
+ // nDeleted: 0,
75
+ // ok: 1,
76
+ // }
77
+ await wo.delAll()
78
+ .then(function(msg) {
79
+ // console.log('delAll then', msg)
80
+ //考慮可能有不同初始測試數據
81
+ // delAll then { n: 2, nDeleted: 2, ok: 1 }
82
+ // delAll then { n: 3, nDeleted: 2, ok: 1 }
83
+ //僅針對nDeleted與ok欄位比對
84
+ rt = {
85
+ nDeleted: msg.nDeleted,
86
+ ok: msg.ok,
87
+ }
88
+ })
89
+ .catch(function(msg) {
90
+ // console.log('delAll catch', msg)
91
+ rt = msg.toString()
92
+ })
93
+ vget[1] = rt
94
+
95
+ //insert
96
+ rt = null
97
+ // vans[2] = { n: 3, nInserted: 3, ok: 1 }
98
+ await wo.insert(rs)
99
+ .then(function(msg) {
100
+ // console.log('insert then', msg)
101
+ // insert then { n: 3, nInserted: 3, ok: 1 }
102
+ rt = msg
103
+ })
104
+ .catch(function(msg) {
105
+ // console.log('insert catch', msg)
106
+ rt = msg.toString()
107
+ })
108
+ vget[2] = rt
109
+
110
+ //save
111
+ rt = null
112
+ // vans[3] = [
113
+ // { n: 1, nModified: 1, ok: 1 },
114
+ // { n: 1, nModified: 1, ok: 1 },
115
+ // { n: 0, nModified: 0, ok: 1 }
116
+ // ]
117
+ await wo.save(rsm, { autoInsert: false })
118
+ .then(function(msg) {
119
+ // console.log('save then', msg)
120
+ // save then [
121
+ // { n: 1, nModified: 1, ok: 1 },
122
+ // { n: 1, nModified: 1, ok: 1 },
123
+ // { n: 0, nModified: 0, ok: 1 }
124
+ // ]
125
+ rt = msg
126
+ })
127
+ .catch(function(msg) {
128
+ // console.log('save catch', msg)
129
+ rt = msg.toString()
130
+ })
131
+ vget[3] = rt
132
+
133
+ //select all
134
+ rt = null
135
+ // vans[4] = [
136
+ // {
137
+ // // id: {random id},
138
+ // name: 'kettle',
139
+ // value: 456
140
+ // },
141
+ // { id: 'id-peter', name: 'peter(modify)', value: 123 },
142
+ // { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 },
143
+ // ]
144
+ await wo.select()
145
+ .then(function(msg) {
146
+ // console.log('select all then', msg)
147
+ msg = _.sortBy(msg, 'name')
148
+ // select all [
149
+ // {
150
+ // id: {random id},
151
+ // name: 'kettle',
152
+ // value: 456
153
+ // },
154
+ // { id: 'id-peter', name: 'peter(modify)', value: 123 },
155
+ // { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
156
+ // ]
157
+ rt = [
158
+ {
159
+ name: msg[0].name,
160
+ value: msg[0].value,
161
+ },
162
+ msg[1],
163
+ msg[2],
164
+ ]
165
+ })
166
+ .catch(function(msg) {
167
+ // console.log('select all catch', msg)
168
+ rt = msg.toString()
169
+ })
170
+ vget[4] = rt
171
+
172
+ //select
173
+ rt = null
174
+ // vans[5] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
175
+ await wo.select({ id: 'id-rosemary' })
176
+ .then(function(msg) {
177
+ // console.log('select then', msg)
178
+ // select [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
179
+ rt = msg
180
+ })
181
+ .catch(function(msg) {
182
+ // console.log('select catch', msg)
183
+ rt = msg.toString()
184
+ })
185
+ vget[5] = rt
186
+
187
+ //select by $and, $gt, $lt
188
+ rt = null
189
+ // vans[6] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
190
+ await wo.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
191
+ .then(function(msg) {
192
+ // console.log('select by $and, $gt, $lt then', msg)
193
+ // select by $and, $gt, $lt [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
194
+ rt = msg
195
+ })
196
+ .catch(function(msg) {
197
+ // console.log('select by $and, $gt, $lt catch', msg)
198
+ rt = msg.toString()
199
+ })
200
+ vget[6] = rt
201
+
202
+ //select by $or, $gte, $lte
203
+ rt = null
204
+ // vans[7] = [
205
+ // {
206
+ // // id: {random id},
207
+ // name: 'kettle',
208
+ // value: 456
209
+ // }
210
+ // ]
211
+ await wo.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
212
+ .then(function(msg) {
213
+ // console.log('select by $or, $gte, $lte then', msg)
214
+ // select by $or, $gte, $lte [
215
+ // {
216
+ // id: {random id},
217
+ // name: 'kettle',
218
+ // value: 456
219
+ // }
220
+ // ]
221
+ rt = [
222
+ {
223
+ name: msg[0].name,
224
+ value: msg[0].value,
225
+ },
226
+ ]
227
+ })
228
+ .catch(function(msg) {
229
+ // console.log('select by $or, $gte, $lte catch', msg)
230
+ rt = msg.toString()
231
+ })
232
+ vget[7] = rt
233
+
234
+ //select by $or, $and, $ne, $in, $nin
235
+ rt = null
236
+ // vans[8] = [
237
+ // {
238
+ // id: 'id-rosemary',
239
+ // name: 'rosemary(modify)',
240
+ // value: 123.456
241
+ // },
242
+ // {
243
+ // // id: {random id},
244
+ // name: 'kettle',
245
+ // value: 456
246
+ // }
247
+ // ]
248
+ 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 } }] }] })
249
+ .then(function(msg) {
250
+ // console.log('select by $or, $and, $ne, $in, $nin then', msg)
251
+ msg = _.sortBy(msg, 'name')
252
+ // select by $or, $and, $ne, $in, $nin [
253
+ // {
254
+ // id: 'id-rosemary',
255
+ // name: 'rosemary(modify)',
256
+ // value: 123.456
257
+ // },
258
+ // {
259
+ // id: {random id},
260
+ // name: 'kettle',
261
+ // value: 456
262
+ // }
263
+ // ]
264
+ rt = [
265
+ {
266
+ name: msg[0].name,
267
+ value: msg[0].value,
268
+ },
269
+ msg[1],
270
+ ]
271
+ })
272
+ .catch(function(msg) {
273
+ // console.log('select by $or, $and, $ne, $in, $nin catch', msg)
274
+ rt = msg.toString()
275
+ })
276
+ vget[8] = rt
277
+
278
+ // //select by regex
279
+ // rt = null
280
+ // vans[9] = [{ id: 'id-peter', name: 'peter(modify)', value: 123 }]
281
+ // await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
282
+ // .then(function(msg) {
283
+ // // console.log('select by regex then', msg)
284
+ // // selectReg [ { id: 'id-peter', name: 'peter(modify)', value: 123 } ]
285
+ // rt = msg
286
+ // })
287
+ // .catch(function(msg) {
288
+ // // console.log('select by regex catch', msg)
289
+ // rt = msg.toString()
290
+ // })
291
+ // vget[9] = rt
292
+
293
+ //save
294
+ rt = null
295
+ // vans[10] = [ { n: 1, nModified: 1, ok: 1 } ]
296
+ await wo.save(rsa, { autoInsert: true })
297
+ .then(function(msg) {
298
+ // console.log('save then', msg)
299
+ // save then [
300
+ // { n: 1, nModified: 1, ok: 1 },
301
+ // { n: 1, nModified: 1, ok: 1 },
302
+ // { n: 0, nModified: 0, ok: 1 }
303
+ // ]
304
+ rt = msg
305
+ })
306
+ .catch(function(msg) {
307
+ // console.log('save catch', msg)
308
+ rt = msg.toString()
309
+ })
310
+ vget[10] = rt
311
+
312
+ //del
313
+ rt = null
314
+ // vans[11] = [{ n: 1, nDeleted: 1, ok: 1 }]
315
+ let ss = await wo.select()
316
+ let d = ss.filter(function(v) {
317
+ return v.name === 'kettle'
423
318
  })
319
+ await wo.del(d)
320
+ .then(function(msg) {
321
+ // console.log('del then', msg)
322
+ // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
323
+ rt = msg
324
+ })
325
+ .catch(function(msg) {
326
+ // console.log('del catch', msg)
327
+ rt = msg.toString()
328
+ })
329
+ vget[11] = rt
424
330
 
425
331
  })
426
- }
332
+
333
+ vans[1] = {
334
+ nDeleted: 0,
335
+ ok: 1,
336
+ }
337
+ it(`should get ${JSON.stringify(vans[1])} for delAll`, async function() {
338
+ assert.strict.deepStrictEqual(vget[1], vans[1])
339
+ })
340
+
341
+ vans[2] = { n: 3, nInserted: 3, ok: 1 }
342
+ it(`should get ${JSON.stringify(vans[2])} for insert`, async function() {
343
+ assert.strict.deepStrictEqual(vget[2], vans[2])
344
+ })
345
+
346
+ vans[3] = [
347
+ { n: 1, nModified: 1, ok: 1 },
348
+ { n: 1, nModified: 1, ok: 1 },
349
+ { n: 0, nModified: 0, ok: 1 }
350
+ ]
351
+ it(`should get ${JSON.stringify(vans[3])} for save(autoInsert=false)`, async function() {
352
+ assert.strict.deepStrictEqual(vget[3], vans[3])
353
+ })
354
+
355
+ vans[4] = [
356
+ {
357
+ // id: {random id},
358
+ name: 'kettle',
359
+ value: 456
360
+ },
361
+ { id: 'id-peter', name: 'peter(modify)', value: 123 },
362
+ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 },
363
+ ]
364
+ it(`should get ${JSON.stringify(vans[4])} for select all`, async function() {
365
+ assert.strict.deepStrictEqual(vget[4], vans[4])
366
+ })
367
+
368
+ vans[5] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
369
+ it(`should get ${JSON.stringify(vans[5])} for select`, async function() {
370
+ assert.strict.deepStrictEqual(vget[5], vans[5])
371
+ })
372
+
373
+ vans[6] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
374
+ it(`should get ${JSON.stringify(vans[6])} for select by $and, $gt, $lt`, async function() {
375
+ assert.strict.deepStrictEqual(vget[6], vans[6])
376
+ })
377
+
378
+ vans[7] = [
379
+ {
380
+ // id: {random id},
381
+ name: 'kettle',
382
+ value: 456
383
+ }
384
+ ]
385
+ it(`should get ${JSON.stringify(vans[7])} for select by $or, $gte, $lte`, async function() {
386
+ assert.strict.deepStrictEqual(vget[7], vans[7])
387
+ })
388
+
389
+ vans[8] = [
390
+ {
391
+ // id: {random id},
392
+ name: 'kettle',
393
+ value: 456
394
+ },
395
+ {
396
+ id: 'id-rosemary',
397
+ name: 'rosemary(modify)',
398
+ value: 123.456
399
+ }
400
+ ]
401
+ it(`should get ${JSON.stringify(vans[8])} for select by $or, $and, $ne, $in, $nin`, async function() {
402
+ assert.strict.deepStrictEqual(vget[8], vans[8])
403
+ })
404
+
405
+ // vans[9] = [{ id: 'id-peter', name: 'peter(modify)', value: 123 }]
406
+ // it(`should get ${JSON.stringify(vans[9])} for select by regex`, async function() {
407
+ // assert.strict.deepStrictEqual(vget[9], vans[9])
408
+ // })
409
+
410
+ vans[10] = [{ n: 1, nModified: 1, ok: 1 }]
411
+ it(`should get ${JSON.stringify(vans[10])} for save(autoInsert=true)`, async function() {
412
+ assert.strict.deepStrictEqual(vget[10], vans[10])
413
+ })
414
+
415
+ vans[11] = [{ n: 1, nDeleted: 1, ok: 1 }]
416
+ it(`should get ${JSON.stringify(vans[11])} for del`, async function() {
417
+ assert.strict.deepStrictEqual(vget[11], vans[11])
418
+ })
419
+
420
+ })
427
421