w-orm-mongodb 1.1.20 → 1.1.24

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/g-gfs.mjs ADDED
@@ -0,0 +1,101 @@
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+ import wo from './src/WOrmMongodb.mjs'
4
+ //import wo from './dist/w-orm-mongodb.umd.js'
5
+
6
+
7
+ let opt = {
8
+ url: 'mongodb://username:password@127.0.0.1:27017',
9
+ db: 'worm',
10
+ cl: 'usersGfs',
11
+ }
12
+
13
+ async function test() {
14
+
15
+
16
+ //w
17
+ let w = wo(opt)
18
+
19
+
20
+ //on
21
+ w.on('change', function(mode, data, res) {
22
+ console.log('change', mode)
23
+ })
24
+
25
+
26
+ //fn_in, fn_out
27
+ let fn_in = path.resolve('../', './_data', 'data(in).dat')
28
+ let fn_out = path.resolve('../', './_data', 'data(out).dat')
29
+
30
+
31
+ //unlinkSync
32
+ fs.unlinkSync(fn_out)
33
+
34
+
35
+ //u8a
36
+ let b = await fs.readFileSync(fn_in)
37
+ let u8a = new Uint8Array(b)
38
+ // let u8a = new Uint8Array([66, 97, 115]) //Uint8Array data from nodejs or browser
39
+ console.log('u8a', u8a)
40
+
41
+
42
+ //delAllGfs
43
+ await w.delAllGfs()
44
+ .then(function(msg) {
45
+ console.log('delAllGfs then', msg)
46
+ })
47
+ .catch(function(msg) {
48
+ console.log('delAllGfs catch', msg)
49
+ })
50
+
51
+
52
+ //insertGfs
53
+ let gi = await w.insertGfs(u8a)
54
+ console.log('insertGfs', gi)
55
+
56
+
57
+ //selectGfs
58
+ let gs = await w.selectGfs(gi.id)
59
+ console.log('selectGfs', gs)
60
+ fs.writeFileSync(fn_out, gs)
61
+
62
+
63
+ //delGfs
64
+ let gd = await w.delGfs(gi.id)
65
+ console.log('delGfs', gd)
66
+
67
+
68
+ }
69
+ test()
70
+ // u8a Uint8Array(47381362) [
71
+ // 0, 0, 0, 24, 102, 116, 121, 112, 109, 112, 52, 50,
72
+ // 0, 0, 0, 0, 105, 115, 111, 109, 109, 112, 52, 50,
73
+ // 0, 2, 14, 73, 109, 111, 111, 118, 0, 0, 0, 108,
74
+ // 109, 118, 104, 100, 0, 0, 0, 0, 214, 15, 24, 167,
75
+ // 214, 15, 24, 167, 0, 1, 95, 144, 1, 106, 95, 88,
76
+ // 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
77
+ // 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
78
+ // 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
79
+ // 0, 0, 0, 0,
80
+ // ... 47381262 more items
81
+ // ]
82
+ // change delAllGfs
83
+ // delAllGfs then { n: 0, ok: 1 }
84
+ // change insertGfs
85
+ // insertGfs { n: 1, ok: 1, id: {random id} }
86
+ // selectGfs Uint8Array(47381362) [
87
+ // 0, 0, 0, 24, 102, 116, 121, 112, 109, 112, 52, 50,
88
+ // 0, 0, 0, 0, 105, 115, 111, 109, 109, 112, 52, 50,
89
+ // 0, 2, 14, 73, 109, 111, 111, 118, 0, 0, 0, 108,
90
+ // 109, 118, 104, 100, 0, 0, 0, 0, 214, 15, 24, 167,
91
+ // 214, 15, 24, 167, 0, 1, 95, 144, 1, 106, 95, 88,
92
+ // 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
93
+ // 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
94
+ // 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
95
+ // 0, 0, 0, 0,
96
+ // ... 47381262 more items
97
+ // ]
98
+ // change delGfs
99
+ // delGfs { n: 1, nDeleted: 1, ok: 1 }
100
+
101
+ //node --experimental-modules --es-module-specifier-resolution=node g-gfs.mjs
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "w-orm-mongodb",
3
- "version": "1.1.20",
4
- "description": "An object of operator for mongodb in nodejs, like a simple ORM.",
3
+ "version": "1.1.24",
4
+ "description": "An object of operator for mongodb in nodejs.",
5
5
  "main": "dist/w-orm-mongodb.umd.js",
6
6
  "dependencies": {
7
- "mongodb": "^3.6.2",
7
+ "mongodb": "^4.1.4",
8
8
  "saslprep": "^1.0.3",
9
- "lodash": "^4.17.20",
10
- "wsemi": "^1.5.26"
9
+ "lodash": "^4.17.21",
10
+ "wsemi": "^1.6.31"
11
11
  },
12
12
  "devDependencies": {
13
- "w-package-tools": "^1.0.30"
13
+ "w-package-tools": "^1.0.59"
14
14
  },
15
15
  "scripts": {
16
- "test": "./node_modules/.bin/mocha --require @babel/register",
16
+ "test": "mocha --parallel --timeout 60000 --experimental-modules --es-module-specifier-resolution=node",
17
17
  "deploy": "gh-pages -d docs"
18
18
  },
19
19
  "repository": {
@@ -139,7 +139,11 @@ function WOrmMongodb(opt = {}) {
139
139
 
140
140
  //check
141
141
  if (res.insertedCount > 0) {
142
- res = res.result
142
+ res = {
143
+ n: size(data),
144
+ nInserted: res.insertedCount,
145
+ ok: res.acknowledged ? 1 : 0,
146
+ }
143
147
  pm.resolve(res)
144
148
  ee.emit('change', 'insert', data, res)
145
149
  }
@@ -199,11 +203,12 @@ function WOrmMongodb(opt = {}) {
199
203
  }
200
204
 
201
205
  //pmSeries
202
- pmSeries(data, function(v) {
206
+ pmSeries(data, async(v) => {
203
207
  let pmm = genPm()
204
208
 
205
209
  //oper
206
210
  collection[oper]({ id: v.id }, { $set: v }, function(err, res) {
211
+ // console.log(oper, 'res', res)
207
212
  if (err) {
208
213
  pmm.reject(err)
209
214
  }
@@ -211,18 +216,39 @@ function WOrmMongodb(opt = {}) {
211
216
 
212
217
  //lastErrorObject for findOneAndUpdate
213
218
  if (res.lastErrorObject) {
214
- res.result = {
219
+ // console.log('res.lastErrorObject', res.lastErrorObject)
220
+ res = {
221
+ // lastErrorObject: { n: 1, updatedExisting: true },
222
+ // value: {
223
+ // _id: new ObjectId("615c18bb6e5db9935b10d88e"),
224
+ // id: 'id-rosemary',
225
+ // name: 'rosemary',
226
+ // value: 123.456
227
+ // },
228
+ // ok: 1
215
229
  n: res.lastErrorObject.n,
216
230
  nModified: res.lastErrorObject.updatedExisting ? 1 : 0,
217
231
  ok: 1,
218
232
  }
219
233
  }
234
+ else {
235
+ res = {
236
+ // acknowledged: true,
237
+ // modifiedCount: 1,
238
+ // upsertedId: null,
239
+ // upsertedCount: 0,
240
+ // matchedCount: 1
241
+ n: res.matchedCount,
242
+ nModified: res.modifiedCount,
243
+ ok: res.acknowledged ? 1 : 0,
244
+ }
245
+ }
246
+ // console.log('res', res)
220
247
 
221
248
  //autoInsert
222
- if (autoInsert && res.result.n === 0) {
249
+ if (autoInsert && res.n === 0) {
223
250
  insert(v)
224
251
  .then(function(res) {
225
- res.nInserted = 1
226
252
  pmm.resolve(res)
227
253
  })
228
254
  .catch(function(err) {
@@ -230,7 +256,7 @@ function WOrmMongodb(opt = {}) {
230
256
  })
231
257
  }
232
258
  else {
233
- pmm.resolve(res.result)
259
+ pmm.resolve(res)
234
260
  }
235
261
 
236
262
  }
@@ -291,8 +317,11 @@ function WOrmMongodb(opt = {}) {
291
317
  pmm.resolve(err) //找不到數據刪除採resovle回傳
292
318
  }
293
319
  else {
294
- res = res.result
295
- res.nDeleted = 1
320
+ res = {
321
+ n: res.deletedCount,
322
+ nDeleted: res.deletedCount,
323
+ ok: res.acknowledged ? 1 : 0,
324
+ }
296
325
  pmm.resolve(res)
297
326
  }
298
327
  })
@@ -340,7 +369,11 @@ function WOrmMongodb(opt = {}) {
340
369
  pm.resolve(err) //找不到數據刪除採resovle回傳
341
370
  }
342
371
  else {
343
- res = res.result
372
+ res = {
373
+ n: res.deletedCount,
374
+ nDeleted: res.deletedCount,
375
+ ok: res.acknowledged ? 1 : 0,
376
+ }
344
377
  pm.resolve(res)
345
378
  ee.emit('change', 'delAll', null, res)
346
379
  }
@@ -559,7 +592,11 @@ function WOrmMongodb(opt = {}) {
559
592
  pm.reject(err)
560
593
  }
561
594
  else {
562
- let res = { n: 1, nDeleted: 1, ok: 1 }
595
+ let res = {
596
+ n: 1,
597
+ nDeleted: 1,
598
+ ok: 1,
599
+ }
563
600
 
564
601
  //resolve
565
602
  pm.resolve(res)
@@ -588,7 +625,11 @@ function WOrmMongodb(opt = {}) {
588
625
  pm.reject(err)
589
626
  }
590
627
  else {
591
- pm.resolve({ n: 1, nDeleted: 1, ok: 1 })
628
+ pm.resolve({
629
+ n: 1,
630
+ nDeleted: 1,
631
+ ok: 1,
632
+ })
592
633
  }
593
634
  })
594
635
 
File without changes
package/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "13"
4
- install:
5
- - npm install
package/sclb.mjs DELETED
@@ -1,64 +0,0 @@
1
- import wo from './src/WOrmMongodb.mjs'
2
- //import wo from './dist/w-orm-mongodb.umd.js'
3
- import fs from 'fs'
4
-
5
-
6
- let opt = {
7
- url: 'mongodb://username:password@127.0.0.1:27017',
8
- db: 'worm',
9
- cl: 'usersGfs',
10
- }
11
-
12
- async function test() {
13
-
14
-
15
- //w
16
- let w = wo(opt)
17
-
18
-
19
- //on
20
- w.on('change', function(mode, data, res) {
21
- console.log('change', mode)
22
- })
23
-
24
-
25
- //fn_in, fn_out
26
- let fn_in = 'D:\\開源-JS-004-2-w-orm-mongodb\\data(in).dat'
27
- let fn_out = 'D:\\開源-JS-004-2-w-orm-mongodb\\data(out).dat'
28
-
29
-
30
- //u8a
31
- let b = await fs.readFileSync(fn_in)
32
- let u8a = new Uint8Array(b)
33
- // let u8a = new Uint8Array([66, 97, 115]) //Uint8Array data from nodejs or browser
34
- console.log('u8a', u8a)
35
-
36
-
37
- //delAllGfs
38
- await w.delAllGfs()
39
- .then(function(msg) {
40
- console.log('delAllGfs then', msg)
41
- })
42
- .catch(function(msg) {
43
- console.log('delAllGfs catch', msg)
44
- })
45
-
46
-
47
- //insertGfs
48
- let gi = await w.insertGfs(u8a)
49
- console.log('insertGfs', gi)
50
-
51
-
52
- //selectGfs
53
- let gs = await w.selectGfs(gi.id)
54
- console.log('selectGfs', gs)
55
- fs.writeFileSync(fn_out, gs)
56
-
57
-
58
- //delGfs
59
- let gd = await w.delGfs(gi.id)
60
- console.log('delGfs', gd)
61
-
62
-
63
- }
64
- test()