w-orm-postgresql 1.0.1 → 1.0.3
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 +108 -5
- package/babel.config.js +4 -3
- package/dist/w-orm-postgresql.umd.js +2 -2
- package/dist/w-orm-postgresql.umd.js.map +1 -1
- package/docs/WOrmPostgresql.html +48 -8
- package/docs/WOrmPostgresql.mjs.html +123 -13
- package/docs/index.html +1 -1
- package/g-basic.mjs +106 -5
- package/package.json +5 -5
- package/script.txt +0 -1
- package/src/WOrmPostgresql.mjs +122 -12
- package/test/basic.test.mjs +681 -428
package/test/basic.test.mjs
CHANGED
|
@@ -1,428 +1,681 @@
|
|
|
1
|
-
import assert from 'assert'
|
|
2
|
-
import WOrm from '../src/WOrmPostgresql.mjs'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
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
|
-
|
|
160
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
.then
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
.catch
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
// console.log('
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
}
|
|
428
|
-
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import WOrm from '../src/WOrmPostgresql.mjs'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
describe('basic', function() {
|
|
6
|
+
let rt = null
|
|
7
|
+
let vans = {}
|
|
8
|
+
let vget = {}
|
|
9
|
+
|
|
10
|
+
before(async function () {
|
|
11
|
+
|
|
12
|
+
let opt = {
|
|
13
|
+
url: 'postgresql://username:password@127.0.0.1:5432',
|
|
14
|
+
db: 'worm',
|
|
15
|
+
cl: 'users',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//probe, 偵測postgres是否可用, 不可用則skip全部測試
|
|
19
|
+
//pg預設無connect timeout, 連不到時會等到OS socket timeout (~75s), 故用Promise.race包3s timeout
|
|
20
|
+
try {
|
|
21
|
+
let probe = WOrm(opt)
|
|
22
|
+
await Promise.race([
|
|
23
|
+
probe.select(),
|
|
24
|
+
new Promise((_resolve, reject) => setTimeout(() => reject(new Error('probe timeout')), 3000)),
|
|
25
|
+
])
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
let msg = err && err.message ? err.message : err
|
|
29
|
+
console.log(`PostgreSQL unavailable, skip tests: ${msg}`)
|
|
30
|
+
this.skip()
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let rs = [
|
|
35
|
+
{
|
|
36
|
+
time: '2025-01-01T00:00:00Z',
|
|
37
|
+
name: 'peter',
|
|
38
|
+
value: 123,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
time: '2025-01-01T00:01:00Z',
|
|
42
|
+
name: 'rosemary',
|
|
43
|
+
value: 123.456,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
time: '2025-01-01T00:02:00Z',
|
|
47
|
+
name: 'kettle',
|
|
48
|
+
value: 456,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
time: '2025-01-01T00:03:00Z',
|
|
52
|
+
name: 'peter',
|
|
53
|
+
value: 200,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
time: '2025-01-01T00:04:00Z',
|
|
57
|
+
name: 'rosemary',
|
|
58
|
+
value: 123.1236,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
time: '2025-01-01T00:05:00Z',
|
|
62
|
+
name: 'kettle',
|
|
63
|
+
value: 488,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
time: '2025-01-01T00:06:00Z',
|
|
67
|
+
name: 'peter',
|
|
68
|
+
value: 125,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
time: '2025-01-01T00:07:00Z',
|
|
72
|
+
name: 'rosemary',
|
|
73
|
+
value: 124.76,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
time: '2025-01-01T00:08:00Z',
|
|
77
|
+
name: 'kettle',
|
|
78
|
+
value: 524,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
time: '2025-01-01T00:09:00Z',
|
|
82
|
+
name: 'peter',
|
|
83
|
+
value: 127,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
time: '2025-01-01T00:10:00Z',
|
|
87
|
+
name: 'rosemary',
|
|
88
|
+
value: 113.98,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
time: '2025-01-01T00:11:00Z',
|
|
92
|
+
name: 'kettle',
|
|
93
|
+
value: 447,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
time: '2025-01-01T00:12:00Z',
|
|
97
|
+
name: 'peter',
|
|
98
|
+
value: 131,
|
|
99
|
+
},
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
let rsm = [
|
|
103
|
+
{ //相同
|
|
104
|
+
time: '2025-01-01T00:09:00Z',
|
|
105
|
+
name: 'peter',
|
|
106
|
+
value: 127,
|
|
107
|
+
},
|
|
108
|
+
{ //name變更
|
|
109
|
+
time: '2025-01-01T00:10:00Z',
|
|
110
|
+
name: 'rosemary(modify)',
|
|
111
|
+
value: 113.98,
|
|
112
|
+
},
|
|
113
|
+
{ //name變更
|
|
114
|
+
time: '2025-01-01T00:11:00Z',
|
|
115
|
+
name: 'kettle(modify)',
|
|
116
|
+
value: 447,
|
|
117
|
+
},
|
|
118
|
+
{ //無name且value變更
|
|
119
|
+
time: '2025-01-01T00:12:00Z',
|
|
120
|
+
// name: 'peter',
|
|
121
|
+
value: 99,
|
|
122
|
+
},
|
|
123
|
+
{ //無time須新增且新增數據無value
|
|
124
|
+
time: '2025-01-01T00:13:00Z',
|
|
125
|
+
name: 'sandler',
|
|
126
|
+
},
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
let rsa = [
|
|
130
|
+
{
|
|
131
|
+
time: '2025-01-01T00:13:00Z',
|
|
132
|
+
name: 'sandler',
|
|
133
|
+
},
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
//wo
|
|
137
|
+
let wo = WOrm(opt)
|
|
138
|
+
|
|
139
|
+
//on
|
|
140
|
+
wo.on('change', function(mode, data, res) {
|
|
141
|
+
// console.log('change', mode)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
await wo.createTable(opt.cl, 'time', {
|
|
145
|
+
time: '2000-01-01T00:00:00Z', //time
|
|
146
|
+
name: 'abc', //string
|
|
147
|
+
value: 0.1, //float
|
|
148
|
+
})
|
|
149
|
+
.then(function(msg) {
|
|
150
|
+
// console.log('createTable then', msg)
|
|
151
|
+
})
|
|
152
|
+
.catch(function(msg) {
|
|
153
|
+
// console.log('createTable catch', msg)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
//delAll
|
|
157
|
+
rt = null
|
|
158
|
+
// vans[1] = { ok: 1 }
|
|
159
|
+
await wo.delAll()
|
|
160
|
+
.then(function(msg) {
|
|
161
|
+
// console.log('delAll then', msg)
|
|
162
|
+
//考慮有不同初始狀態, 僅比對ok欄位
|
|
163
|
+
rt = {
|
|
164
|
+
ok: msg.ok,
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
.catch(function(msg) {
|
|
168
|
+
// console.log('delAll catch', msg)
|
|
169
|
+
rt = msg.toString()
|
|
170
|
+
})
|
|
171
|
+
vget[1] = rt
|
|
172
|
+
|
|
173
|
+
//insert
|
|
174
|
+
rt = null
|
|
175
|
+
// vans[2] = { n: 13, nInserted: 13, ok: 1 }
|
|
176
|
+
await wo.insert(rs)
|
|
177
|
+
.then(function(msg) {
|
|
178
|
+
// console.log('insert then', msg)
|
|
179
|
+
rt = msg
|
|
180
|
+
})
|
|
181
|
+
.catch(function(msg) {
|
|
182
|
+
// console.log('insert catch', msg)
|
|
183
|
+
rt = msg.toString()
|
|
184
|
+
})
|
|
185
|
+
vget[2] = rt
|
|
186
|
+
|
|
187
|
+
//save
|
|
188
|
+
rt = null
|
|
189
|
+
// vans[3] = [
|
|
190
|
+
// { n: 1, nModified: 0, ok: 1 },
|
|
191
|
+
// { n: 1, nModified: 1, ok: 1 },
|
|
192
|
+
// { n: 1, nModified: 1, ok: 1 },
|
|
193
|
+
// { n: 1, nModified: 1, ok: 1 },
|
|
194
|
+
// { n: 0, nModified: 0, ok: 1 }
|
|
195
|
+
// ]
|
|
196
|
+
await wo.save(rsm, { autoInsert: false })
|
|
197
|
+
.then(function(msg) {
|
|
198
|
+
// console.log('save then', msg)
|
|
199
|
+
rt = msg
|
|
200
|
+
})
|
|
201
|
+
.catch(function(msg) {
|
|
202
|
+
// console.log('save catch', msg)
|
|
203
|
+
rt = msg.toString()
|
|
204
|
+
})
|
|
205
|
+
vget[3] = rt
|
|
206
|
+
|
|
207
|
+
//select all
|
|
208
|
+
rt = null
|
|
209
|
+
// vans[4] = [
|
|
210
|
+
// { time: new Date('2025-01-01T00:00:00.000Z'), name: 'peter', value: 123 },
|
|
211
|
+
// { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
212
|
+
// { time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
213
|
+
// { time: new Date('2025-01-01T00:03:00.000Z'), name: 'peter', value: 200 },
|
|
214
|
+
// { time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
|
|
215
|
+
// { time: new Date('2025-01-01T00:05:00.000Z'), name: 'kettle', value: 488 },
|
|
216
|
+
// { time: new Date('2025-01-01T00:06:00.000Z'), name: 'peter', value: 125 },
|
|
217
|
+
// { time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 },
|
|
218
|
+
// { time: new Date('2025-01-01T00:08:00.000Z'), name: 'kettle', value: 524 },
|
|
219
|
+
// { time: new Date('2025-01-01T00:09:00.000Z'), name: 'peter', value: 127 },
|
|
220
|
+
// { time: new Date('2025-01-01T00:10:00.000Z'), name: 'rosemary(modify)', value: 113.98 },
|
|
221
|
+
// { time: new Date('2025-01-01T00:11:00.000Z'), name: 'kettle(modify)', value: 447 },
|
|
222
|
+
// { time: new Date('2025-01-01T00:12:00.000Z'), name: 'peter', value: 99 }
|
|
223
|
+
// ]
|
|
224
|
+
await wo.select()
|
|
225
|
+
.then(function(msg) {
|
|
226
|
+
// console.log('select all then', msg)
|
|
227
|
+
rt = msg
|
|
228
|
+
})
|
|
229
|
+
.catch(function(msg) {
|
|
230
|
+
// console.log('select all catch', msg)
|
|
231
|
+
rt = msg.toString()
|
|
232
|
+
})
|
|
233
|
+
vget[4] = rt
|
|
234
|
+
|
|
235
|
+
//select all by cache
|
|
236
|
+
rt = null
|
|
237
|
+
// vans[5] = vans[4]
|
|
238
|
+
await wo.select()
|
|
239
|
+
.then(function(msg) {
|
|
240
|
+
// console.log('select all by cache then', msg)
|
|
241
|
+
rt = msg
|
|
242
|
+
})
|
|
243
|
+
.catch(function(msg) {
|
|
244
|
+
// console.log('select all by cache catch', msg)
|
|
245
|
+
rt = msg.toString()
|
|
246
|
+
})
|
|
247
|
+
vget[5] = rt
|
|
248
|
+
|
|
249
|
+
//select by name
|
|
250
|
+
rt = null
|
|
251
|
+
// vans[6] = [
|
|
252
|
+
// { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
253
|
+
// { time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
|
|
254
|
+
// { time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 }
|
|
255
|
+
// ]
|
|
256
|
+
await wo.select({ name: 'rosemary' })
|
|
257
|
+
.then(function(msg) {
|
|
258
|
+
// console.log('select all then', msg)
|
|
259
|
+
rt = msg
|
|
260
|
+
})
|
|
261
|
+
.catch(function(msg) {
|
|
262
|
+
// console.log('select all catch', msg)
|
|
263
|
+
rt = msg.toString()
|
|
264
|
+
})
|
|
265
|
+
vget[6] = rt
|
|
266
|
+
|
|
267
|
+
//select by $and, $gt, $lt
|
|
268
|
+
rt = null
|
|
269
|
+
// vans[7] = [
|
|
270
|
+
// { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
271
|
+
// { time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
|
|
272
|
+
// { time: new Date('2025-01-01T00:06:00.000Z'), name: 'peter', value: 125 },
|
|
273
|
+
// { time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 },
|
|
274
|
+
// { time: new Date('2025-01-01T00:09:00.000Z'), name: 'peter', value: 127 }
|
|
275
|
+
// ]
|
|
276
|
+
await wo.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
|
|
277
|
+
.then(function(msg) {
|
|
278
|
+
// console.log('select all then', msg)
|
|
279
|
+
rt = msg
|
|
280
|
+
})
|
|
281
|
+
.catch(function(msg) {
|
|
282
|
+
// console.log('select all catch', msg)
|
|
283
|
+
rt = msg.toString()
|
|
284
|
+
})
|
|
285
|
+
vget[7] = rt
|
|
286
|
+
|
|
287
|
+
//select by $or, $gte, $lte
|
|
288
|
+
rt = null
|
|
289
|
+
// vans[8] = [
|
|
290
|
+
// { time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
291
|
+
// { time: new Date('2025-01-01T00:03:00.000Z'), name: 'peter', value: 200 },
|
|
292
|
+
// { time: new Date('2025-01-01T00:05:00.000Z'), name: 'kettle', value: 488 },
|
|
293
|
+
// { time: new Date('2025-01-01T00:08:00.000Z'), name: 'kettle', value: 524 },
|
|
294
|
+
// { time: new Date('2025-01-01T00:11:00.000Z'), name: 'kettle(modify)', value: 447 }
|
|
295
|
+
// ]
|
|
296
|
+
await wo.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
|
|
297
|
+
.then(function(msg) {
|
|
298
|
+
// console.log('select all then', msg)
|
|
299
|
+
rt = msg
|
|
300
|
+
})
|
|
301
|
+
.catch(function(msg) {
|
|
302
|
+
// console.log('select all catch', msg)
|
|
303
|
+
rt = msg.toString()
|
|
304
|
+
})
|
|
305
|
+
vget[8] = rt
|
|
306
|
+
|
|
307
|
+
//select by $or, $and, $ne, $in, $nin
|
|
308
|
+
rt = null
|
|
309
|
+
// vans[9] = [
|
|
310
|
+
// { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
311
|
+
// { time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
312
|
+
// { time: new Date('2025-01-01T00:05:00.000Z'), name: 'kettle', value: 488 },
|
|
313
|
+
// { time: new Date('2025-01-01T00:08:00.000Z'), name: 'kettle', value: 524 },
|
|
314
|
+
// { time: new Date('2025-01-01T00:11:00.000Z'), name: 'kettle(modify)', value: 447 }
|
|
315
|
+
// ]
|
|
316
|
+
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 } }] }] })
|
|
317
|
+
.then(function(msg) {
|
|
318
|
+
// console.log('select all then', msg)
|
|
319
|
+
rt = msg
|
|
320
|
+
})
|
|
321
|
+
.catch(function(msg) {
|
|
322
|
+
// console.log('select all catch', msg)
|
|
323
|
+
rt = msg.toString()
|
|
324
|
+
})
|
|
325
|
+
vget[9] = rt
|
|
326
|
+
|
|
327
|
+
// //select by regex
|
|
328
|
+
// rt = null
|
|
329
|
+
// vans[14] = []
|
|
330
|
+
// let sr = await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
|
|
331
|
+
// .then(function(msg) {
|
|
332
|
+
// // console.log('select all then', msg)
|
|
333
|
+
// rt = msg
|
|
334
|
+
// })
|
|
335
|
+
// .catch(function(msg) {
|
|
336
|
+
// // console.log('select all catch', msg)
|
|
337
|
+
// rt = msg.toString()
|
|
338
|
+
// })
|
|
339
|
+
// vget[14] = rt
|
|
340
|
+
|
|
341
|
+
//save
|
|
342
|
+
rt = null
|
|
343
|
+
// vans[10] = [{ n: 1, nInserted: 1, ok: 1 }]
|
|
344
|
+
await wo.save(rsa, { autoInsert: true })
|
|
345
|
+
.then(function(msg) {
|
|
346
|
+
// console.log('save then', msg)
|
|
347
|
+
rt = msg
|
|
348
|
+
})
|
|
349
|
+
.catch(function(msg) {
|
|
350
|
+
// console.log('save catch', msg)
|
|
351
|
+
rt = msg.toString()
|
|
352
|
+
})
|
|
353
|
+
vget[10] = rt
|
|
354
|
+
|
|
355
|
+
//del
|
|
356
|
+
rt = null
|
|
357
|
+
// vans[11] = [{ n: 1, nDeleted: 0, ok: 1 }]
|
|
358
|
+
let d = {
|
|
359
|
+
time: '2024-01-01T00:00:00Z',
|
|
360
|
+
}
|
|
361
|
+
await wo.del(d)
|
|
362
|
+
.then(function(msg) {
|
|
363
|
+
// console.log('del then', msg)
|
|
364
|
+
rt = msg
|
|
365
|
+
})
|
|
366
|
+
.catch(function(msg) {
|
|
367
|
+
// console.log('del catch', msg)
|
|
368
|
+
rt = msg.toString()
|
|
369
|
+
})
|
|
370
|
+
vget[11] = rt
|
|
371
|
+
|
|
372
|
+
//del
|
|
373
|
+
rt = null
|
|
374
|
+
// vans[12] = [
|
|
375
|
+
// { n: 1, nDeleted: 1, ok: 1 },
|
|
376
|
+
// { n: 1, nDeleted: 1, ok: 1 },
|
|
377
|
+
// { n: 1, nDeleted: 1, ok: 1 },
|
|
378
|
+
// { n: 1, nDeleted: 1, ok: 1 },
|
|
379
|
+
// { n: 1, nDeleted: 1, ok: 1 },
|
|
380
|
+
// { n: 1, nDeleted: 1, ok: 1 },
|
|
381
|
+
// { n: 1, nDeleted: 1, ok: 1 },
|
|
382
|
+
// { n: 1, nDeleted: 1, ok: 1 },
|
|
383
|
+
// { n: 1, nDeleted: 1, ok: 1 },
|
|
384
|
+
// { n: 1, nDeleted: 1, ok: 1 }
|
|
385
|
+
// ]
|
|
386
|
+
let ss = await wo.select()
|
|
387
|
+
let ds = ss.filter(function(v) {
|
|
388
|
+
return v.name.indexOf('peter') >= 0 || v.name.indexOf('kettle') >= 0 || v.name.indexOf('sandler') >= 0
|
|
389
|
+
})
|
|
390
|
+
await wo.del(ds)
|
|
391
|
+
.then(function(msg) {
|
|
392
|
+
// console.log('del then', msg)
|
|
393
|
+
rt = msg
|
|
394
|
+
})
|
|
395
|
+
.catch(function(msg) {
|
|
396
|
+
// console.log('del catch', msg)
|
|
397
|
+
rt = msg.toString()
|
|
398
|
+
})
|
|
399
|
+
vget[12] = rt
|
|
400
|
+
|
|
401
|
+
//select all final
|
|
402
|
+
rt = null
|
|
403
|
+
// vans[13] = [
|
|
404
|
+
// { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
405
|
+
// { time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
|
|
406
|
+
// { time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 },
|
|
407
|
+
// { time: new Date('2025-01-01T00:10:00.000Z'), name: 'rosemary(modify)', value: 113.98 }
|
|
408
|
+
// ]
|
|
409
|
+
await wo.select()
|
|
410
|
+
.then(function(msg) {
|
|
411
|
+
// console.log('select all then', msg)
|
|
412
|
+
rt = msg
|
|
413
|
+
})
|
|
414
|
+
.catch(function(msg) {
|
|
415
|
+
// console.log('select all catch', msg)
|
|
416
|
+
rt = msg.toString()
|
|
417
|
+
})
|
|
418
|
+
vget[13] = rt
|
|
419
|
+
|
|
420
|
+
//清除數據, 後續cache測試共用users表
|
|
421
|
+
await wo.delAll()
|
|
422
|
+
|
|
423
|
+
//woc, 啟用useCache
|
|
424
|
+
let woc = WOrm({
|
|
425
|
+
...opt,
|
|
426
|
+
useCache: true,
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
let rsc = [
|
|
430
|
+
{
|
|
431
|
+
time: '2025-01-01T00:00:00Z',
|
|
432
|
+
name: 'peter',
|
|
433
|
+
value: 123,
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
time: '2025-01-01T00:01:00Z',
|
|
437
|
+
name: 'rosemary',
|
|
438
|
+
value: 123.456,
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
time: '2025-01-01T00:02:00Z',
|
|
442
|
+
name: 'kettle',
|
|
443
|
+
value: 456,
|
|
444
|
+
},
|
|
445
|
+
]
|
|
446
|
+
|
|
447
|
+
let rscm = [
|
|
448
|
+
{
|
|
449
|
+
time: '2025-01-01T00:01:00Z',
|
|
450
|
+
name: 'rosemary(modify)',
|
|
451
|
+
value: 654.321,
|
|
452
|
+
},
|
|
453
|
+
]
|
|
454
|
+
|
|
455
|
+
//insert
|
|
456
|
+
await woc.insert(rsc)
|
|
457
|
+
|
|
458
|
+
//select all (1st time, 從DB讀取並填入快取)
|
|
459
|
+
rt = null
|
|
460
|
+
// vans[14] = [
|
|
461
|
+
// { time: new Date('2025-01-01T00:00:00.000Z'), name: 'peter', value: 123 },
|
|
462
|
+
// { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
463
|
+
// { time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
464
|
+
// ]
|
|
465
|
+
await woc.select()
|
|
466
|
+
.then(function(msg) {
|
|
467
|
+
// console.log('select 1st then', msg)
|
|
468
|
+
//依time排序, postgres UPDATE後物理順序可能改變
|
|
469
|
+
rt = msg.sort((a, b) => a.time - b.time)
|
|
470
|
+
})
|
|
471
|
+
.catch(function(msg) {
|
|
472
|
+
// console.log('select 1st catch', msg)
|
|
473
|
+
rt = msg.toString()
|
|
474
|
+
})
|
|
475
|
+
vget[14] = rt
|
|
476
|
+
|
|
477
|
+
//select all (2nd time, 命中快取, 內容須與第一次相同)
|
|
478
|
+
rt = null
|
|
479
|
+
// vans[15] = vans[14]
|
|
480
|
+
await woc.select()
|
|
481
|
+
.then(function(msg) {
|
|
482
|
+
// console.log('select 2nd then', msg)
|
|
483
|
+
rt = msg.sort((a, b) => a.time - b.time)
|
|
484
|
+
})
|
|
485
|
+
.catch(function(msg) {
|
|
486
|
+
// console.log('select 2nd catch', msg)
|
|
487
|
+
rt = msg.toString()
|
|
488
|
+
})
|
|
489
|
+
vget[15] = rt
|
|
490
|
+
|
|
491
|
+
//save (更新rosemary, 觸發快取重設)
|
|
492
|
+
rt = null
|
|
493
|
+
// vans[16] = [{ n: 1, nModified: 1, ok: 1 }]
|
|
494
|
+
await woc.save(rscm, { autoInsert: false })
|
|
495
|
+
.then(function(msg) {
|
|
496
|
+
// console.log('save then', msg)
|
|
497
|
+
rt = msg
|
|
498
|
+
})
|
|
499
|
+
.catch(function(msg) {
|
|
500
|
+
// console.log('save catch', msg)
|
|
501
|
+
rt = msg.toString()
|
|
502
|
+
})
|
|
503
|
+
vget[16] = rt
|
|
504
|
+
|
|
505
|
+
//select all (3rd time, 快取已重設, 從DB重新讀取, 須反映rosemary更新)
|
|
506
|
+
rt = null
|
|
507
|
+
// vans[17] = [
|
|
508
|
+
// { time: new Date('2025-01-01T00:00:00.000Z'), name: 'peter', value: 123 },
|
|
509
|
+
// { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary(modify)', value: 654.321 },
|
|
510
|
+
// { time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
511
|
+
// ]
|
|
512
|
+
await woc.select()
|
|
513
|
+
.then(function(msg) {
|
|
514
|
+
// console.log('select 3rd then', msg)
|
|
515
|
+
rt = msg.sort((a, b) => a.time - b.time)
|
|
516
|
+
})
|
|
517
|
+
.catch(function(msg) {
|
|
518
|
+
// console.log('select 3rd catch', msg)
|
|
519
|
+
rt = msg.toString()
|
|
520
|
+
})
|
|
521
|
+
vget[17] = rt
|
|
522
|
+
|
|
523
|
+
})
|
|
524
|
+
|
|
525
|
+
vans[1] = { ok: 1 }
|
|
526
|
+
it(`should get ${JSON.stringify(vans[1])} for delAll`, async function() {
|
|
527
|
+
assert.strict.deepStrictEqual(vget[1], vans[1])
|
|
528
|
+
})
|
|
529
|
+
|
|
530
|
+
vans[2] = { n: 13, nInserted: 13, ok: 1 }
|
|
531
|
+
it(`should get ${JSON.stringify(vans[2])} for insert`, async function() {
|
|
532
|
+
assert.strict.deepStrictEqual(vget[2], vans[2])
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
vans[3] = [
|
|
536
|
+
{ n: 1, nModified: 0, ok: 1 },
|
|
537
|
+
{ n: 1, nModified: 1, ok: 1 },
|
|
538
|
+
{ n: 1, nModified: 1, ok: 1 },
|
|
539
|
+
{ n: 1, nModified: 1, ok: 1 },
|
|
540
|
+
{ n: 0, nModified: 0, ok: 1 }
|
|
541
|
+
]
|
|
542
|
+
it(`should get ${JSON.stringify(vans[3])} for save(autoInsert=false)`, async function() {
|
|
543
|
+
assert.strict.deepStrictEqual(vget[3], vans[3])
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
vans[4] = [
|
|
547
|
+
{ time: new Date('2025-01-01T00:00:00.000Z'), name: 'peter', value: 123 },
|
|
548
|
+
{ time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
549
|
+
{ time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
550
|
+
{ time: new Date('2025-01-01T00:03:00.000Z'), name: 'peter', value: 200 },
|
|
551
|
+
{ time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
|
|
552
|
+
{ time: new Date('2025-01-01T00:05:00.000Z'), name: 'kettle', value: 488 },
|
|
553
|
+
{ time: new Date('2025-01-01T00:06:00.000Z'), name: 'peter', value: 125 },
|
|
554
|
+
{ time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 },
|
|
555
|
+
{ time: new Date('2025-01-01T00:08:00.000Z'), name: 'kettle', value: 524 },
|
|
556
|
+
{ time: new Date('2025-01-01T00:09:00.000Z'), name: 'peter', value: 127 },
|
|
557
|
+
{ time: new Date('2025-01-01T00:10:00.000Z'), name: 'rosemary(modify)', value: 113.98 },
|
|
558
|
+
{ time: new Date('2025-01-01T00:11:00.000Z'), name: 'kettle(modify)', value: 447 },
|
|
559
|
+
{ time: new Date('2025-01-01T00:12:00.000Z'), name: 'peter', value: 99 }
|
|
560
|
+
]
|
|
561
|
+
it(`should get ${JSON.stringify(vans[4])} for select all`, async function() {
|
|
562
|
+
assert.strict.deepStrictEqual(vget[4], vans[4])
|
|
563
|
+
})
|
|
564
|
+
|
|
565
|
+
vans[5] = vans[4]
|
|
566
|
+
it(`should get ${JSON.stringify(vans[5])} for select all by cache`, async function() {
|
|
567
|
+
assert.strict.deepStrictEqual(vget[5], vans[5])
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
vans[6] = [
|
|
571
|
+
{ time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
572
|
+
{ time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
|
|
573
|
+
{ time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 }
|
|
574
|
+
]
|
|
575
|
+
it(`should get ${JSON.stringify(vans[6])} for select by name`, async function() {
|
|
576
|
+
assert.strict.deepStrictEqual(vget[6], vans[6])
|
|
577
|
+
})
|
|
578
|
+
|
|
579
|
+
vans[7] = [
|
|
580
|
+
{ time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
581
|
+
{ time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
|
|
582
|
+
{ time: new Date('2025-01-01T00:06:00.000Z'), name: 'peter', value: 125 },
|
|
583
|
+
{ time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 },
|
|
584
|
+
{ time: new Date('2025-01-01T00:09:00.000Z'), name: 'peter', value: 127 }
|
|
585
|
+
]
|
|
586
|
+
it(`should get ${JSON.stringify(vans[7])} for select by $and, $gt, $lt`, async function() {
|
|
587
|
+
assert.strict.deepStrictEqual(vget[7], vans[7])
|
|
588
|
+
})
|
|
589
|
+
|
|
590
|
+
vans[8] = [
|
|
591
|
+
{ time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
592
|
+
{ time: new Date('2025-01-01T00:03:00.000Z'), name: 'peter', value: 200 },
|
|
593
|
+
{ time: new Date('2025-01-01T00:05:00.000Z'), name: 'kettle', value: 488 },
|
|
594
|
+
{ time: new Date('2025-01-01T00:08:00.000Z'), name: 'kettle', value: 524 },
|
|
595
|
+
{ time: new Date('2025-01-01T00:11:00.000Z'), name: 'kettle(modify)', value: 447 }
|
|
596
|
+
]
|
|
597
|
+
it(`should get ${JSON.stringify(vans[8])} for select by $or, $gte, $lte`, async function() {
|
|
598
|
+
assert.strict.deepStrictEqual(vget[8], vans[8])
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
vans[9] = [
|
|
602
|
+
{ time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
603
|
+
{ time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
604
|
+
{ time: new Date('2025-01-01T00:05:00.000Z'), name: 'kettle', value: 488 },
|
|
605
|
+
{ time: new Date('2025-01-01T00:08:00.000Z'), name: 'kettle', value: 524 },
|
|
606
|
+
{ time: new Date('2025-01-01T00:11:00.000Z'), name: 'kettle(modify)', value: 447 }
|
|
607
|
+
]
|
|
608
|
+
it(`should get ${JSON.stringify(vans[9])} for select by $or, $and, $ne, $in, $nin`, async function() {
|
|
609
|
+
assert.strict.deepStrictEqual(vget[9], vans[9])
|
|
610
|
+
})
|
|
611
|
+
|
|
612
|
+
// vans[14] = []
|
|
613
|
+
// it(`should get ${JSON.stringify(vans[14])} for select by regex`, async function() {
|
|
614
|
+
// assert.strict.deepStrictEqual(vget[14], vans[14])
|
|
615
|
+
// })
|
|
616
|
+
|
|
617
|
+
vans[10] = [{ n: 1, nInserted: 1, ok: 1 }]
|
|
618
|
+
it(`should get ${JSON.stringify(vans[10])} for save(autoInsert=true)`, async function() {
|
|
619
|
+
assert.strict.deepStrictEqual(vget[10], vans[10])
|
|
620
|
+
})
|
|
621
|
+
|
|
622
|
+
vans[11] = [{ n: 1, nDeleted: 0, ok: 1 }]
|
|
623
|
+
it(`should get ${JSON.stringify(vans[11])} for del`, async function() {
|
|
624
|
+
assert.strict.deepStrictEqual(vget[11], vans[11])
|
|
625
|
+
})
|
|
626
|
+
|
|
627
|
+
vans[12] = [
|
|
628
|
+
{ n: 1, nDeleted: 1, ok: 1 },
|
|
629
|
+
{ n: 1, nDeleted: 1, ok: 1 },
|
|
630
|
+
{ n: 1, nDeleted: 1, ok: 1 },
|
|
631
|
+
{ n: 1, nDeleted: 1, ok: 1 },
|
|
632
|
+
{ n: 1, nDeleted: 1, ok: 1 },
|
|
633
|
+
{ n: 1, nDeleted: 1, ok: 1 },
|
|
634
|
+
{ n: 1, nDeleted: 1, ok: 1 },
|
|
635
|
+
{ n: 1, nDeleted: 1, ok: 1 },
|
|
636
|
+
{ n: 1, nDeleted: 1, ok: 1 },
|
|
637
|
+
{ n: 1, nDeleted: 1, ok: 1 }
|
|
638
|
+
]
|
|
639
|
+
it(`should get ${JSON.stringify(vans[12])} for del`, async function() {
|
|
640
|
+
assert.strict.deepStrictEqual(vget[12], vans[12])
|
|
641
|
+
})
|
|
642
|
+
|
|
643
|
+
vans[13] = [
|
|
644
|
+
{ time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
645
|
+
{ time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
|
|
646
|
+
{ time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 },
|
|
647
|
+
{ time: new Date('2025-01-01T00:10:00.000Z'), name: 'rosemary(modify)', value: 113.98 }
|
|
648
|
+
]
|
|
649
|
+
it(`should get ${JSON.stringify(vans[13])} for select all final`, async function() {
|
|
650
|
+
assert.strict.deepStrictEqual(vget[13], vans[13])
|
|
651
|
+
})
|
|
652
|
+
|
|
653
|
+
vans[14] = [
|
|
654
|
+
{ time: new Date('2025-01-01T00:00:00.000Z'), name: 'peter', value: 123 },
|
|
655
|
+
{ time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
|
|
656
|
+
{ time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
657
|
+
]
|
|
658
|
+
it(`should get ${JSON.stringify(vans[14])} for select all (1st, fill cache)`, async function() {
|
|
659
|
+
assert.strict.deepStrictEqual(vget[14], vans[14])
|
|
660
|
+
})
|
|
661
|
+
|
|
662
|
+
vans[15] = vans[14]
|
|
663
|
+
it(`should get ${JSON.stringify(vans[15])} for select all (2nd, cache hit)`, async function() {
|
|
664
|
+
assert.strict.deepStrictEqual(vget[15], vans[15])
|
|
665
|
+
})
|
|
666
|
+
|
|
667
|
+
vans[16] = [{ n: 1, nModified: 1, ok: 1 }]
|
|
668
|
+
it(`should get ${JSON.stringify(vans[16])} for save (invalidate cache)`, async function() {
|
|
669
|
+
assert.strict.deepStrictEqual(vget[16], vans[16])
|
|
670
|
+
})
|
|
671
|
+
|
|
672
|
+
vans[17] = [
|
|
673
|
+
{ time: new Date('2025-01-01T00:00:00.000Z'), name: 'peter', value: 123 },
|
|
674
|
+
{ time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary(modify)', value: 654.321 },
|
|
675
|
+
{ time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
|
|
676
|
+
]
|
|
677
|
+
it(`should get ${JSON.stringify(vans[17])} for select all (3rd, reload after save)`, async function() {
|
|
678
|
+
assert.strict.deepStrictEqual(vget[17], vans[17])
|
|
679
|
+
})
|
|
680
|
+
|
|
681
|
+
})
|