w-orm-postgresql 1.0.2 → 1.0.4
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 +148 -65
- 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 +216 -196
- package/docs/index.html +1 -1
- package/g-basic.mjs +148 -65
- package/package.json +3 -3
- package/src/WOrmPostgresql.mjs +215 -195
- package/test/basic.test.mjs +666 -455
package/g-basic.mjs
CHANGED
|
@@ -76,7 +76,7 @@ let rs = [
|
|
|
76
76
|
},
|
|
77
77
|
]
|
|
78
78
|
|
|
79
|
-
let rsm = [
|
|
79
|
+
let rsm = [
|
|
80
80
|
{ //相同
|
|
81
81
|
time: '2025-01-01T00:09:00Z',
|
|
82
82
|
name: 'peter',
|
|
@@ -100,17 +100,17 @@ let rsm = [
|
|
|
100
100
|
{ //無time須新增且新增數據無value
|
|
101
101
|
time: '2025-01-01T00:13:00Z',
|
|
102
102
|
name: 'sandler',
|
|
103
|
-
},
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
let rsa = [
|
|
107
|
-
{
|
|
108
|
-
time: '2025-01-01T00:13:00Z',
|
|
109
|
-
name: 'sandler',
|
|
110
|
-
},
|
|
111
|
-
]
|
|
112
|
-
|
|
113
|
-
async function test() {
|
|
103
|
+
},
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
let rsa = [
|
|
107
|
+
{
|
|
108
|
+
time: '2025-01-01T00:13:00Z',
|
|
109
|
+
name: 'sandler',
|
|
110
|
+
},
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
async function test() {
|
|
114
114
|
|
|
115
115
|
//wo
|
|
116
116
|
let wo = WOrm(opt)
|
|
@@ -151,18 +151,18 @@ async function test() {
|
|
|
151
151
|
console.log('insert catch', msg)
|
|
152
152
|
})
|
|
153
153
|
|
|
154
|
-
//save
|
|
155
|
-
await wo.save(rsm, { autoInsert: false })
|
|
156
|
-
.then(function(msg) {
|
|
157
|
-
console.log('save then', msg)
|
|
158
|
-
})
|
|
159
|
-
.catch(function(msg) {
|
|
160
|
-
console.log('save catch', msg)
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
//select all
|
|
164
|
-
let ss = await wo.select()
|
|
165
|
-
console.log('select all', ss)
|
|
154
|
+
//save
|
|
155
|
+
await wo.save(rsm, { autoInsert: false })
|
|
156
|
+
.then(function(msg) {
|
|
157
|
+
console.log('save then', msg)
|
|
158
|
+
})
|
|
159
|
+
.catch(function(msg) {
|
|
160
|
+
console.log('save catch', msg)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
//select all
|
|
164
|
+
let ss = await wo.select()
|
|
165
|
+
console.log('select all', ss)
|
|
166
166
|
|
|
167
167
|
//select
|
|
168
168
|
let so = await wo.select({ name: 'rosemary' })
|
|
@@ -180,22 +180,22 @@ async function test() {
|
|
|
180
180
|
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 } }] }] })
|
|
181
181
|
console.log('select by $or, $and, $ne, $in, $nin', spc)
|
|
182
182
|
|
|
183
|
-
// //select by regex
|
|
184
|
-
// let sr = await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
|
|
185
|
-
// console.log('selectReg', sr)
|
|
186
|
-
|
|
187
|
-
//save
|
|
188
|
-
await wo.save(rsa, { autoInsert: true })
|
|
189
|
-
.then(function(msg) {
|
|
190
|
-
console.log('save then', msg)
|
|
191
|
-
})
|
|
192
|
-
.catch(function(msg) {
|
|
193
|
-
console.log('save catch', msg)
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
//del
|
|
197
|
-
let d = {
|
|
198
|
-
time: '2024-01-01T00:00:00Z',
|
|
183
|
+
// //select by regex
|
|
184
|
+
// let sr = await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
|
|
185
|
+
// console.log('selectReg', sr)
|
|
186
|
+
|
|
187
|
+
//save
|
|
188
|
+
await wo.save(rsa, { autoInsert: true })
|
|
189
|
+
.then(function(msg) {
|
|
190
|
+
console.log('save then', msg)
|
|
191
|
+
})
|
|
192
|
+
.catch(function(msg) {
|
|
193
|
+
console.log('save catch', msg)
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
//del
|
|
197
|
+
let d = {
|
|
198
|
+
time: '2024-01-01T00:00:00Z',
|
|
199
199
|
}
|
|
200
200
|
await wo.del(d)
|
|
201
201
|
.then(function(msg) {
|
|
@@ -203,13 +203,13 @@ async function test() {
|
|
|
203
203
|
})
|
|
204
204
|
.catch(function(msg) {
|
|
205
205
|
console.log('del catch', msg)
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
//del
|
|
209
|
-
let ssDel = await wo.select()
|
|
210
|
-
let ds = ssDel.filter(function(v) {
|
|
211
|
-
return v.name.indexOf('peter') >= 0 || v.name.indexOf('kettle') >= 0 || v.name.indexOf('sandler') >= 0
|
|
212
|
-
})
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
//del
|
|
209
|
+
let ssDel = await wo.select()
|
|
210
|
+
let ds = ssDel.filter(function(v) {
|
|
211
|
+
return v.name.indexOf('peter') >= 0 || v.name.indexOf('kettle') >= 0 || v.name.indexOf('sandler') >= 0
|
|
212
|
+
})
|
|
213
213
|
await wo.del(ds)
|
|
214
214
|
.then(function(msg) {
|
|
215
215
|
console.log('del then', msg)
|
|
@@ -222,6 +222,68 @@ async function test() {
|
|
|
222
222
|
let ss2 = await wo.select()
|
|
223
223
|
console.log('select all final', ss2)
|
|
224
224
|
|
|
225
|
+
//清除數據, 後續cache測試共用users表
|
|
226
|
+
await wo.delAll()
|
|
227
|
+
|
|
228
|
+
//woc, 啟用useCache
|
|
229
|
+
let woc = WOrm({
|
|
230
|
+
...opt,
|
|
231
|
+
useCache: true,
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
let rsc = [
|
|
235
|
+
{
|
|
236
|
+
time: '2025-01-01T00:00:00Z',
|
|
237
|
+
name: 'peter',
|
|
238
|
+
value: 123,
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
time: '2025-01-01T00:01:00Z',
|
|
242
|
+
name: 'rosemary',
|
|
243
|
+
value: 123.456,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
time: '2025-01-01T00:02:00Z',
|
|
247
|
+
name: 'kettle',
|
|
248
|
+
value: 456,
|
|
249
|
+
},
|
|
250
|
+
]
|
|
251
|
+
|
|
252
|
+
let rscm = [
|
|
253
|
+
{
|
|
254
|
+
time: '2025-01-01T00:01:00Z',
|
|
255
|
+
name: 'rosemary(modify)',
|
|
256
|
+
value: 654.321,
|
|
257
|
+
},
|
|
258
|
+
]
|
|
259
|
+
|
|
260
|
+
//insert
|
|
261
|
+
await woc.insert(rsc)
|
|
262
|
+
|
|
263
|
+
//select all (1st time, 從DB讀取並填入快取)
|
|
264
|
+
let sc1 = await woc.select()
|
|
265
|
+
sc1 = sc1.sort((a, b) => a.time - b.time)
|
|
266
|
+
console.log('select all 1st (fill cache)', sc1)
|
|
267
|
+
|
|
268
|
+
//select all (2nd time, 命中快取, 內容須與第一次相同)
|
|
269
|
+
let sc2 = await woc.select()
|
|
270
|
+
sc2 = sc2.sort((a, b) => a.time - b.time)
|
|
271
|
+
console.log('select all 2nd (cache hit)', sc2)
|
|
272
|
+
|
|
273
|
+
//save (更新rosemary, 觸發快取重設)
|
|
274
|
+
await woc.save(rscm, { autoInsert: false })
|
|
275
|
+
.then(function(msg) {
|
|
276
|
+
console.log('save (invalidate cache) then', msg)
|
|
277
|
+
})
|
|
278
|
+
.catch(function(msg) {
|
|
279
|
+
console.log('save (invalidate cache) catch', msg)
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
//select all (3rd time, 快取已重設, 從DB重新讀取, 須反映rosemary更新)
|
|
283
|
+
let sc3 = await woc.select()
|
|
284
|
+
sc3 = sc3.sort((a, b) => a.time - b.time)
|
|
285
|
+
console.log('select all 3rd (reload after save)', sc3)
|
|
286
|
+
|
|
225
287
|
}
|
|
226
288
|
test()
|
|
227
289
|
// change delAll
|
|
@@ -230,13 +292,13 @@ test()
|
|
|
230
292
|
// insert then { n: 13, nInserted: 13, ok: 1 }
|
|
231
293
|
// change save
|
|
232
294
|
// save then [
|
|
233
|
-
// { n: 1, nModified: 0, ok: 1 },
|
|
234
|
-
// { n: 1, nModified: 1, ok: 1 },
|
|
235
|
-
// { n: 1, nModified: 1, ok: 1 },
|
|
236
|
-
// { n: 1, nModified: 1, ok: 1 },
|
|
237
|
-
// { n: 0, nModified: 0, ok: 1 }
|
|
238
|
-
// ]
|
|
239
|
-
// select all [
|
|
295
|
+
// { n: 1, nModified: 0, ok: 1 },
|
|
296
|
+
// { n: 1, nModified: 1, ok: 1 },
|
|
297
|
+
// { n: 1, nModified: 1, ok: 1 },
|
|
298
|
+
// { n: 1, nModified: 1, ok: 1 },
|
|
299
|
+
// { n: 0, nModified: 0, ok: 1 }
|
|
300
|
+
// ]
|
|
301
|
+
// select all [
|
|
240
302
|
// { time: 2025-01-01T00:00:00.000Z, name: 'peter', value: 123 },
|
|
241
303
|
// { time: 2025-01-01T00:01:00.000Z, name: 'rosemary', value: 123.456 },
|
|
242
304
|
// { time: 2025-01-01T00:02:00.000Z, name: 'kettle', value: 456 },
|
|
@@ -255,10 +317,10 @@ test()
|
|
|
255
317
|
// {
|
|
256
318
|
// time: 2025-01-01T00:11:00.000Z,
|
|
257
319
|
// name: 'kettle(modify)',
|
|
258
|
-
// value: 447
|
|
259
|
-
// },
|
|
260
|
-
// { time: 2025-01-01T00:12:00.000Z, name: 'peter', value: 99 }
|
|
261
|
-
// ]
|
|
320
|
+
// value: 447
|
|
321
|
+
// },
|
|
322
|
+
// { time: 2025-01-01T00:12:00.000Z, name: 'peter', value: 99 }
|
|
323
|
+
// ]
|
|
262
324
|
// select by name [
|
|
263
325
|
// { time: 2025-01-01T00:01:00.000Z, name: 'rosemary', value: 123.456 },
|
|
264
326
|
// { time: 2025-01-01T00:04:00.000Z, name: 'rosemary', value: 123.1236 },
|
|
@@ -290,13 +352,13 @@ test()
|
|
|
290
352
|
// {
|
|
291
353
|
// time: 2025-01-01T00:11:00.000Z,
|
|
292
354
|
// name: 'kettle(modify)',
|
|
293
|
-
// value: 447
|
|
294
|
-
// }
|
|
295
|
-
// ]
|
|
296
|
-
// change save
|
|
297
|
-
// save then [ { n: 1, nInserted: 1, ok: 1 } ]
|
|
298
|
-
// change del
|
|
299
|
-
// del then [ { n: 1, nDeleted: 0, ok: 1 } ]
|
|
355
|
+
// value: 447
|
|
356
|
+
// }
|
|
357
|
+
// ]
|
|
358
|
+
// change save
|
|
359
|
+
// save then [ { n: 1, nInserted: 1, ok: 1 } ]
|
|
360
|
+
// change del
|
|
361
|
+
// del then [ { n: 1, nDeleted: 0, ok: 1 } ]
|
|
300
362
|
// change del
|
|
301
363
|
// del then [
|
|
302
364
|
// { n: 1, nDeleted: 1, ok: 1 },
|
|
@@ -320,5 +382,26 @@ test()
|
|
|
320
382
|
// value: 113.98
|
|
321
383
|
// }
|
|
322
384
|
// ]
|
|
385
|
+
// change delAll
|
|
386
|
+
// select all 1st (fill cache) [
|
|
387
|
+
// { time: 2025-01-01T00:00:00.000Z, name: 'peter', value: 123 },
|
|
388
|
+
// { time: 2025-01-01T00:01:00.000Z, name: 'rosemary', value: 123.456 },
|
|
389
|
+
// { time: 2025-01-01T00:02:00.000Z, name: 'kettle', value: 456 }
|
|
390
|
+
// ]
|
|
391
|
+
// select all 2nd (cache hit) [
|
|
392
|
+
// { time: 2025-01-01T00:00:00.000Z, name: 'peter', value: 123 },
|
|
393
|
+
// { time: 2025-01-01T00:01:00.000Z, name: 'rosemary', value: 123.456 },
|
|
394
|
+
// { time: 2025-01-01T00:02:00.000Z, name: 'kettle', value: 456 }
|
|
395
|
+
// ]
|
|
396
|
+
// save (invalidate cache) then [ { n: 1, nModified: 1, ok: 1 } ]
|
|
397
|
+
// select all 3rd (reload after save) [
|
|
398
|
+
// { time: 2025-01-01T00:00:00.000Z, name: 'peter', value: 123 },
|
|
399
|
+
// {
|
|
400
|
+
// time: 2025-01-01T00:01:00.000Z,
|
|
401
|
+
// name: 'rosemary(modify)',
|
|
402
|
+
// value: 654.321
|
|
403
|
+
// },
|
|
404
|
+
// { time: 2025-01-01T00:02:00.000Z, name: 'kettle', value: 456 }
|
|
405
|
+
// ]
|
|
323
406
|
|
|
324
407
|
//node g-basic.mjs
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w-orm-postgresql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "dist/w-orm-postgresql.umd.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"mongo-sql": "^6.2.0",
|
|
7
7
|
"pg": "^8.20.0",
|
|
8
8
|
"lodash-es": "^4.18.1",
|
|
9
|
-
"wsemi": "^1.8.
|
|
9
|
+
"wsemi": "^1.8.66"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"w-package-tools": "^1.1.
|
|
12
|
+
"w-package-tools": "^1.1.11"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"test": "mocha --parallel --timeout 60000",
|