w-orm-postgresql 1.0.0

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.
Files changed (51) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +55 -0
  4. package/.jsdoc +25 -0
  5. package/LICENSE +21 -0
  6. package/README.md +324 -0
  7. package/SECURITY.md +5 -0
  8. package/babel.config.js +15 -0
  9. package/dist/w-orm-postgresql.umd.js +7 -0
  10. package/dist/w-orm-postgresql.umd.js.map +1 -0
  11. package/docs/WOrmPostgresql.html +1655 -0
  12. package/docs/WOrmPostgresql.mjs.html +952 -0
  13. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  14. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  15. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  16. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  17. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  19. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  20. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  21. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  24. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  30. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  31. package/docs/index.html +84 -0
  32. package/docs/scripts/collapse.js +39 -0
  33. package/docs/scripts/commonNav.js +28 -0
  34. package/docs/scripts/linenumber.js +25 -0
  35. package/docs/scripts/nav.js +12 -0
  36. package/docs/scripts/polyfill.js +4 -0
  37. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  38. package/docs/scripts/prettify/lang-css.js +2 -0
  39. package/docs/scripts/prettify/prettify.js +28 -0
  40. package/docs/scripts/search.js +99 -0
  41. package/docs/styles/jsdoc.css +776 -0
  42. package/docs/styles/prettify.css +80 -0
  43. package/g-basic.mjs +306 -0
  44. package/package.json +32 -0
  45. package/script.txt +18 -0
  46. package/src/WOrmPostgresql.mjs +880 -0
  47. package/test/basic.test.mjs +429 -0
  48. package/toolg/addVersion.mjs +4 -0
  49. package/toolg/cleanFolder.mjs +4 -0
  50. package/toolg/gDistRollup.mjs +25 -0
  51. package/toolg/modifyReadme.mjs +4 -0
@@ -0,0 +1,429 @@
1
+ import assert from 'assert'
2
+ import wo from '../src/WOrmPostgresql.mjs'
3
+
4
+
5
+ function isWindows() {
6
+ return process.platform === 'win32'
7
+ }
8
+
9
+
10
+ if (isWindows()) {
11
+ describe('basic', function() {
12
+ let rt = null
13
+ let vans = {}
14
+ let vget = {}
15
+
16
+
17
+ before(async function () {
18
+
19
+ let opt = {
20
+ url: 'postgresql://username:password@127.0.0.1:5432',
21
+ db: 'worm',
22
+ cl: 'users',
23
+ }
24
+
25
+ let rs = [
26
+ {
27
+ time: '2025-01-01T00:00:00Z',
28
+ name: 'peter',
29
+ value: 123,
30
+ },
31
+ {
32
+ time: '2025-01-01T00:01:00Z',
33
+ name: 'rosemary',
34
+ value: 123.456,
35
+ },
36
+ {
37
+ time: '2025-01-01T00:02:00Z',
38
+ name: 'kettle',
39
+ value: 456,
40
+ },
41
+ {
42
+ time: '2025-01-01T00:03:00Z',
43
+ name: 'peter',
44
+ value: 200,
45
+ },
46
+ {
47
+ time: '2025-01-01T00:04:00Z',
48
+ name: 'rosemary',
49
+ value: 123.1236,
50
+ },
51
+ {
52
+ time: '2025-01-01T00:05:00Z',
53
+ name: 'kettle',
54
+ value: 488,
55
+ },
56
+ {
57
+ time: '2025-01-01T00:06:00Z',
58
+ name: 'peter',
59
+ value: 125,
60
+ },
61
+ {
62
+ time: '2025-01-01T00:07:00Z',
63
+ name: 'rosemary',
64
+ value: 124.76,
65
+ },
66
+ {
67
+ time: '2025-01-01T00:08:00Z',
68
+ name: 'kettle',
69
+ value: 524,
70
+ },
71
+ {
72
+ time: '2025-01-01T00:09:00Z',
73
+ name: 'peter',
74
+ value: 127,
75
+ },
76
+ {
77
+ time: '2025-01-01T00:10:00Z',
78
+ name: 'rosemary',
79
+ value: 113.98,
80
+ },
81
+ {
82
+ time: '2025-01-01T00:11:00Z',
83
+ name: 'kettle',
84
+ value: 447,
85
+ },
86
+ {
87
+ time: '2025-01-01T00:12:00Z',
88
+ name: 'peter',
89
+ value: 131,
90
+ },
91
+ ]
92
+
93
+ let rsm = [
94
+ { //相同
95
+ time: '2025-01-01T00:09:00Z',
96
+ name: 'peter',
97
+ value: 127,
98
+ },
99
+ { //name變更
100
+ time: '2025-01-01T00:10:00Z',
101
+ name: 'rosemary(modify)',
102
+ value: 113.98,
103
+ },
104
+ { //name變更
105
+ time: '2025-01-01T00:11:00Z',
106
+ name: 'kettle(modify)',
107
+ value: 447,
108
+ },
109
+ { //無name且value變更
110
+ time: '2025-01-01T00:12:00Z',
111
+ // name: 'peter',
112
+ value: 99,
113
+ },
114
+ { //無time須新增且新增數據無value
115
+ time: '2025-01-01T00:13:00Z',
116
+ name: 'sandler',
117
+ },
118
+ ]
119
+
120
+ //w
121
+ let w = wo(opt)
122
+
123
+ //on
124
+ w.on('change', function(mode, data, res) {
125
+ // console.log('change', mode)
126
+ })
127
+
128
+ await w.createTable(opt.cl, 'time', {
129
+ time: '2000-01-01T00:00:00Z', //time
130
+ name: 'abc', //string
131
+ value: 0.1, //float
132
+ })
133
+ .then(function(msg) {
134
+ // console.log('createTable then', msg)
135
+ })
136
+ .catch(function(msg) {
137
+ // console.log('createTable catch', msg)
138
+ })
139
+
140
+ //delAll
141
+ rt = null
142
+ vans[1] = { ok: 1 }
143
+ await w.delAll()
144
+ .then(function(msg) {
145
+ // console.log('delAll then', msg)
146
+ //考慮有不同初始狀態, 僅比對ok欄位
147
+ rt = {
148
+ ok: msg.ok,
149
+ }
150
+ })
151
+ .catch(function(msg) {
152
+ // console.log('delAll catch', msg)
153
+ rt = msg.toString()
154
+ })
155
+ vget[1] = rt
156
+
157
+ //insert
158
+ rt = null
159
+ vans[2] = { n: 13, nInserted: 13, ok: 1 }
160
+ await w.insert(rs)
161
+ .then(function(msg) {
162
+ // console.log('insert then', msg)
163
+ rt = msg
164
+ })
165
+ .catch(function(msg) {
166
+ // console.log('insert catch', msg)
167
+ rt = msg.toString()
168
+ })
169
+ vget[2] = rt
170
+
171
+ //save
172
+ rt = null
173
+ vans[3] = [
174
+ { n: 1, nModified: 0, ok: 1 },
175
+ { n: 1, nModified: 1, ok: 1 },
176
+ { n: 1, nModified: 1, ok: 1 },
177
+ { n: 1, nModified: 1, ok: 1 },
178
+ { n: 1, nInserted: 1, ok: 1 }
179
+ ]
180
+ await w.save(rsm, { autoInsert: true })
181
+ .then(function(msg) {
182
+ // console.log('save then', msg)
183
+ rt = msg
184
+ })
185
+ .catch(function(msg) {
186
+ // console.log('save catch', msg)
187
+ rt = msg.toString()
188
+ })
189
+ vget[3] = rt
190
+
191
+ //select all
192
+ rt = null
193
+ vans[4] = [
194
+ { time: new Date('2025-01-01T00:00:00.000Z'), name: 'peter', value: 123 },
195
+ { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
196
+ { time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
197
+ { time: new Date('2025-01-01T00:03:00.000Z'), name: 'peter', value: 200 },
198
+ { time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
199
+ { time: new Date('2025-01-01T00:05:00.000Z'), name: 'kettle', value: 488 },
200
+ { time: new Date('2025-01-01T00:06:00.000Z'), name: 'peter', value: 125 },
201
+ { time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 },
202
+ { time: new Date('2025-01-01T00:08:00.000Z'), name: 'kettle', value: 524 },
203
+ { time: new Date('2025-01-01T00:09:00.000Z'), name: 'peter', value: 127 },
204
+ { time: new Date('2025-01-01T00:10:00.000Z'), name: 'rosemary(modify)', value: 113.98 },
205
+ { time: new Date('2025-01-01T00:11:00.000Z'), name: 'kettle(modify)', value: 447 },
206
+ { time: new Date('2025-01-01T00:12:00.000Z'), name: 'peter', value: 99 },
207
+ { time: new Date('2025-01-01T00:13:00.000Z'), name: 'sandler', value: null }
208
+ ]
209
+ await w.select()
210
+ .then(function(msg) {
211
+ // console.log('select all then', msg)
212
+ rt = msg
213
+ })
214
+ .catch(function(msg) {
215
+ // console.log('select all catch', msg)
216
+ rt = msg.toString()
217
+ })
218
+ vget[4] = rt
219
+
220
+ //select by name
221
+ rt = null
222
+ vans[5] = [
223
+ { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
224
+ { time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
225
+ { time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 }
226
+ ]
227
+ await w.select({ name: 'rosemary' })
228
+ .then(function(msg) {
229
+ // console.log('select all then', msg)
230
+ rt = msg
231
+ })
232
+ .catch(function(msg) {
233
+ // console.log('select all catch', msg)
234
+ rt = msg.toString()
235
+ })
236
+ vget[5] = rt
237
+
238
+ //select by $and, $gt, $lt
239
+ rt = null
240
+ vans[6] = [
241
+ { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
242
+ { time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
243
+ { time: new Date('2025-01-01T00:06:00.000Z'), name: 'peter', value: 125 },
244
+ { time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 },
245
+ { time: new Date('2025-01-01T00:09:00.000Z'), name: 'peter', value: 127 }
246
+ ]
247
+ await w.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
248
+ .then(function(msg) {
249
+ // console.log('select all then', msg)
250
+ rt = msg
251
+ })
252
+ .catch(function(msg) {
253
+ // console.log('select all catch', msg)
254
+ rt = msg.toString()
255
+ })
256
+ vget[6] = rt
257
+
258
+ //select by $or, $gte, $lte
259
+ rt = null
260
+ vans[7] = [
261
+ { time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
262
+ { time: new Date('2025-01-01T00:03:00.000Z'), name: 'peter', value: 200 },
263
+ { time: new Date('2025-01-01T00:05:00.000Z'), name: 'kettle', value: 488 },
264
+ { time: new Date('2025-01-01T00:08:00.000Z'), name: 'kettle', value: 524 },
265
+ { time: new Date('2025-01-01T00:11:00.000Z'), name: 'kettle(modify)', value: 447 }
266
+ ]
267
+ await w.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
268
+ .then(function(msg) {
269
+ // console.log('select all then', msg)
270
+ rt = msg
271
+ })
272
+ .catch(function(msg) {
273
+ // console.log('select all catch', msg)
274
+ rt = msg.toString()
275
+ })
276
+ vget[7] = rt
277
+
278
+ //select by $or, $and, $ne, $in, $nin
279
+ rt = null
280
+ vans[8] = [
281
+ { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
282
+ { time: new Date('2025-01-01T00:02:00.000Z'), name: 'kettle', value: 456 },
283
+ { time: new Date('2025-01-01T00:05:00.000Z'), name: 'kettle', value: 488 },
284
+ { time: new Date('2025-01-01T00:08:00.000Z'), name: 'kettle', value: 524 },
285
+ { time: new Date('2025-01-01T00:11:00.000Z'), name: 'kettle(modify)', value: 447 }
286
+ ]
287
+ await w.select({ '$or': [{ '$and': [{ value: { '$ne': 123 } }, { value: { '$in': [123, 321, 123.456, 456] } }, { value: { '$nin': [456, 654] } }] }, { '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 400 } }] }] })
288
+ .then(function(msg) {
289
+ // console.log('select all then', msg)
290
+ rt = msg
291
+ })
292
+ .catch(function(msg) {
293
+ // console.log('select all catch', msg)
294
+ rt = msg.toString()
295
+ })
296
+ vget[8] = rt
297
+
298
+ // //select by regex
299
+ // rt = null
300
+ // vans[9] = []
301
+ // let sr = await w.select({ name: { $regex: 'PeT', $options: '$i' } })
302
+ // .then(function(msg) {
303
+ // // console.log('select all then', msg)
304
+ // rt = msg
305
+ // })
306
+ // .catch(function(msg) {
307
+ // // console.log('select all catch', msg)
308
+ // rt = msg.toString()
309
+ // })
310
+ // vget[9] = rt
311
+
312
+ //del
313
+ rt = null
314
+ vans[10] = [{ n: 1, nDeleted: 0, ok: 1 }]
315
+ let d = {
316
+ time: '2024-01-01T00:00:00Z',
317
+ }
318
+ await w.del(d)
319
+ .then(function(msg) {
320
+ // console.log('del then', msg)
321
+ rt = msg
322
+ })
323
+ .catch(function(msg) {
324
+ // console.log('del catch', msg)
325
+ rt = msg.toString()
326
+ })
327
+ vget[10] = rt
328
+
329
+ //del
330
+ rt = null
331
+ vans[11] = [
332
+ { n: 1, nDeleted: 1, ok: 1 },
333
+ { n: 1, nDeleted: 1, ok: 1 },
334
+ { n: 1, nDeleted: 1, ok: 1 },
335
+ { n: 1, nDeleted: 1, ok: 1 },
336
+ { n: 1, nDeleted: 1, ok: 1 },
337
+ { n: 1, nDeleted: 1, ok: 1 },
338
+ { n: 1, nDeleted: 1, ok: 1 },
339
+ { n: 1, nDeleted: 1, ok: 1 },
340
+ { n: 1, nDeleted: 1, ok: 1 },
341
+ { n: 1, nDeleted: 1, ok: 1 }
342
+ ]
343
+ let ss = await w.select()
344
+ let ds = ss.filter(function(v) {
345
+ return v.name.indexOf('peter') >= 0 || v.name.indexOf('kettle') >= 0 || v.name.indexOf('sandler') >= 0
346
+ })
347
+ await w.del(ds)
348
+ .then(function(msg) {
349
+ // console.log('del then', msg)
350
+ rt = msg
351
+ })
352
+ .catch(function(msg) {
353
+ // console.log('del catch', msg)
354
+ rt = msg.toString()
355
+ })
356
+ vget[11] = rt
357
+
358
+ //select all final
359
+ rt = null
360
+ vans[12] = [
361
+ { time: new Date('2025-01-01T00:01:00.000Z'), name: 'rosemary', value: 123.456 },
362
+ { time: new Date('2025-01-01T00:04:00.000Z'), name: 'rosemary', value: 123.1236 },
363
+ { time: new Date('2025-01-01T00:07:00.000Z'), name: 'rosemary', value: 124.76 },
364
+ { time: new Date('2025-01-01T00:10:00.000Z'), name: 'rosemary(modify)', value: 113.98 }
365
+ ]
366
+ await w.select()
367
+ .then(function(msg) {
368
+ // console.log('select all then', msg)
369
+ rt = msg
370
+ })
371
+ .catch(function(msg) {
372
+ // console.log('select all catch', msg)
373
+ rt = msg.toString()
374
+ })
375
+ vget[12] = rt
376
+
377
+ })
378
+
379
+ it(`should get ${JSON.stringify(vans[1])} for delAll`, async function() {
380
+ assert.strict.deepStrictEqual(vget[1], vans[1])
381
+ })
382
+
383
+ it(`should get ${JSON.stringify(vans[2])} for insert`, async function() {
384
+ assert.strict.deepStrictEqual(vget[2], vans[2])
385
+ })
386
+
387
+ it(`should get ${JSON.stringify(vans[3])} for save`, async function() {
388
+ assert.strict.deepStrictEqual(vget[3], vans[3])
389
+ })
390
+
391
+ it(`should get ${JSON.stringify(vans[4])} for select all`, async function() {
392
+ assert.strict.deepStrictEqual(vget[4], vans[4])
393
+ })
394
+
395
+ it(`should get ${JSON.stringify(vans[5])} for select by name`, async function() {
396
+ assert.strict.deepStrictEqual(vget[5], vans[5])
397
+ })
398
+
399
+ it(`should get ${JSON.stringify(vans[6])} for select by $and, $gt, $lt`, async function() {
400
+ assert.strict.deepStrictEqual(vget[6], vans[6])
401
+ })
402
+
403
+ it(`should get ${JSON.stringify(vans[7])} for select by $or, $gte, $lte`, async function() {
404
+ assert.strict.deepStrictEqual(vget[7], vans[7])
405
+ })
406
+
407
+ it(`should get ${JSON.stringify(vans[8])} for select by $or, $and, $ne, $in, $nin`, async function() {
408
+ assert.strict.deepStrictEqual(vget[8], vans[8])
409
+ })
410
+
411
+ // it(`should get ${JSON.stringify(vans[9])} for select by regex`, async function() {
412
+ // assert.strict.deepStrictEqual(vget[9], vans[9])
413
+ // })
414
+
415
+ it(`should get ${JSON.stringify(vans[10])} for del`, async function() {
416
+ assert.strict.deepStrictEqual(vget[10], vans[10])
417
+ })
418
+
419
+ it(`should get ${JSON.stringify(vans[11])} for del`, async function() {
420
+ assert.strict.deepStrictEqual(vget[11], vans[11])
421
+ })
422
+
423
+ it(`should get ${JSON.stringify(vans[12])} for select all final`, async function() {
424
+ assert.strict.deepStrictEqual(vget[12], vans[12])
425
+ })
426
+
427
+ })
428
+ }
429
+
@@ -0,0 +1,4 @@
1
+ import addVersion from 'w-package-tools/src/addVersion.mjs'
2
+
3
+
4
+ addVersion()
@@ -0,0 +1,4 @@
1
+ import cleanFolder from 'w-package-tools/src/cleanFolder.mjs'
2
+
3
+
4
+ cleanFolder('docs')
@@ -0,0 +1,25 @@
1
+ import rollupFiles from 'w-package-tools/src/rollupFiles.mjs'
2
+ import getFiles from 'w-package-tools/src/getFiles.mjs'
3
+
4
+
5
+ let fdSrc = './src'
6
+ let fdTar = './dist'
7
+
8
+
9
+ rollupFiles({
10
+ fns: getFiles(fdSrc),
11
+ fdSrc,
12
+ fdTar,
13
+ nameDistType: 'kebabCase',
14
+ globals: {
15
+ 'events': 'events',
16
+ 'pg': 'pg',
17
+ 'mongo-sql': 'mongo-sql',
18
+ },
19
+ external: [
20
+ 'events',
21
+ 'pg',
22
+ 'mongo-sql',
23
+ ],
24
+ })
25
+
@@ -0,0 +1,4 @@
1
+ import modifyReadme from 'w-package-tools/src/modifyReadme.mjs'
2
+
3
+
4
+ modifyReadme()