multi-db-orm 2.1.6 → 2.1.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.
package/restore.js CHANGED
@@ -1,102 +1,102 @@
1
-
2
- const mongoose = require('mongoose');
3
- var fs = require('fs');
4
- async function log(arg) {
5
- update(arg)
6
- }
7
-
8
- var maxC = 0;
9
- var curC = 1;
10
- async function processCollection(collectionName) {
11
-
12
- try {
13
-
14
- var collData = data[collectionName];
15
- var coll = db.collection(collectionName);
16
- collData.forEach((cd) => {
17
- cd._id = mongoose.Types.ObjectId(cd._id)
18
- })
19
- await coll.insertMany(collData)
20
- var count = await coll.countDocuments()
21
- log(collectionName, " = ", count);
22
- if(removeDups)
23
- dups(collectionName)
24
-
25
- } catch (er) {
26
- log(er.message)
27
- log("error in " + collectionName);
28
- }
29
- log('Processed '+collectionName+"("+(curC+"/"+maxC)+")");
30
- if (curC++ < maxC) {
31
- curC;
32
- }
33
- else {
34
- log("\n\nAll Data restore completed !!");
35
- finish('Restore Complete !')
36
- }
37
-
38
- };
39
-
40
- async function dups(collectionName) {
41
- var coll = db.collection(collectionName);
42
- await coll.aggregate(
43
- { "$group": { "_id": "$name", "count": { "$sum": 1 } } },
44
- { "$match": { "_id": { "$ne": null }, "count": { "$gt": 1 } } },
45
- { "$project": { "name": "$_id", "_id": 0 } }
46
- )
47
- .toArray((err, results) => {
48
- if (err) throw err;
49
- log("===", results);
50
-
51
- })
52
- }
53
-
54
- var dumpFile = process.argv[2];
55
- var targetDb = process.argv[3];
56
- var deDupDo = process.argv[4];
57
- var db;
58
- var data;
59
- var update=(msg)=>{
60
- console.log(msg)
61
- }
62
- var finish=(msg)=>{
63
- log(msg)
64
- process.exit()
65
- }
66
- var removeDups=false;
67
- if (dumpFile && targetDb) {
68
- data = JSON.parse(fs.readFileSync(dumpFile));
69
- mongoose.Promise = global.Promise;
70
-
71
- mongoose.connect(targetDb, {
72
- useUnifiedTopology: true,
73
- useNewUrlParser: true,
74
- }).then(() => {
75
- log("Successfully connected to the database");
76
- readCollectionsFromDump(mongoose.connection.db,JSON.parse(fs.readFileSync(dumpFile)),deDupDo);
77
- }).catch(err => {
78
- log('Could not connect to the database. Exiting now...', err);
79
- process.exit();
80
- });
81
- }
82
- async function readCollectionsFromDump(connectedDB, dumpData,deDup) {
83
-
84
-
85
- if(deDup==1){
86
- removeDups=true;
87
- log("Removing duplicates as well")
88
- }
89
- db = connectedDB;
90
- data = (dumpData);
91
-
92
- var v = Object.keys(dumpData)
93
- log('Found '+v.length+' Collections to restore');
94
- // log(v);
95
- maxC = v.length;
96
- console.log(v.length)
97
- v.forEach(async function(coll){
98
- await processCollection(coll)
99
- });
100
-
101
-
102
- }
1
+
2
+ const mongoose = require('mongoose');
3
+ var fs = require('fs');
4
+ async function log(arg) {
5
+ update(arg)
6
+ }
7
+
8
+ var maxC = 0;
9
+ var curC = 1;
10
+ async function processCollection(collectionName) {
11
+
12
+ try {
13
+
14
+ var collData = data[collectionName];
15
+ var coll = db.collection(collectionName);
16
+ collData.forEach((cd) => {
17
+ cd._id = mongoose.Types.ObjectId(cd._id)
18
+ })
19
+ await coll.insertMany(collData)
20
+ var count = await coll.countDocuments()
21
+ log(collectionName, " = ", count);
22
+ if(removeDups)
23
+ dups(collectionName)
24
+
25
+ } catch (er) {
26
+ log(er.message)
27
+ log("error in " + collectionName);
28
+ }
29
+ log('Processed '+collectionName+"("+(curC+"/"+maxC)+")");
30
+ if (curC++ < maxC) {
31
+ curC;
32
+ }
33
+ else {
34
+ log("\n\nAll Data restore completed !!");
35
+ finish('Restore Complete !')
36
+ }
37
+
38
+ };
39
+
40
+ async function dups(collectionName) {
41
+ var coll = db.collection(collectionName);
42
+ await coll.aggregate(
43
+ { "$group": { "_id": "$name", "count": { "$sum": 1 } } },
44
+ { "$match": { "_id": { "$ne": null }, "count": { "$gt": 1 } } },
45
+ { "$project": { "name": "$_id", "_id": 0 } }
46
+ )
47
+ .toArray((err, results) => {
48
+ if (err) throw err;
49
+ log("===", results);
50
+
51
+ })
52
+ }
53
+
54
+ var dumpFile = process.argv[2];
55
+ var targetDb = process.argv[3];
56
+ var deDupDo = process.argv[4];
57
+ var db;
58
+ var data;
59
+ var update=(msg)=>{
60
+ console.log(msg)
61
+ }
62
+ var finish=(msg)=>{
63
+ log(msg)
64
+ process.exit()
65
+ }
66
+ var removeDups=false;
67
+ if (dumpFile && targetDb) {
68
+ data = JSON.parse(fs.readFileSync(dumpFile));
69
+ mongoose.Promise = global.Promise;
70
+
71
+ mongoose.connect(targetDb, {
72
+ useUnifiedTopology: true,
73
+ useNewUrlParser: true,
74
+ }).then(() => {
75
+ log("Successfully connected to the database");
76
+ readCollectionsFromDump(mongoose.connection.db,JSON.parse(fs.readFileSync(dumpFile)),deDupDo);
77
+ }).catch(err => {
78
+ log('Could not connect to the database. Exiting now...', err);
79
+ process.exit();
80
+ });
81
+ }
82
+ async function readCollectionsFromDump(connectedDB, dumpData,deDup) {
83
+
84
+
85
+ if(deDup==1){
86
+ removeDups=true;
87
+ log("Removing duplicates as well")
88
+ }
89
+ db = connectedDB;
90
+ data = (dumpData);
91
+
92
+ var v = Object.keys(dumpData)
93
+ log('Found '+v.length+' Collections to restore');
94
+ // log(v);
95
+ maxC = v.length;
96
+ console.log(v.length)
97
+ v.forEach(async function(coll){
98
+ await processCollection(coll)
99
+ });
100
+
101
+
102
+ }
package/sync.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export class Sync {
2
- create(modelname: string, sampleObject: any): void;
3
- insert(modelname: string, object: any): void;
4
- update(modelname: string, filter: any, object: any): void;
5
- delete(modelname: string, filter: any): void;
1
+ export class Sync {
2
+ create(modelname: string, sampleObject: any): void;
3
+ insert(modelname: string, object: any): void;
4
+ update(modelname: string, filter: any, object: any): void;
5
+ delete(modelname: string, filter: any): void;
6
6
  }
package/sync.js CHANGED
@@ -1,49 +1,49 @@
1
- try {
2
- var bkp = require('./backup')
3
- var rst = require('./restore')
4
- } catch (e) {
5
- console.log('Warning : Multi region sync not enabled.' )
6
- }
7
-
8
- class Sync {
9
-
10
- loglevel = 1
11
-
12
- constructor(){
13
-
14
- }
15
-
16
- async create(modelname, object) {
17
- if (this.loglevel > 4)
18
- console.log("Not implemented")
19
- }
20
-
21
- async insert(modelname, object) {
22
- if (this.loglevel > 4)
23
- console.log("Not implemented")
24
- }
25
-
26
- async update(modelname, filter, object) {
27
- if (this.loglevel > 4)
28
- console.log("Not implemented")
29
- }
30
-
31
- async delete(modelname, filter) {
32
- if (this.loglevel > 4)
33
- console.log("Not implemented")
34
- }
35
-
36
- backup(...args) {
37
- bkp(args)
38
- }
39
-
40
- restore(...args) {
41
- rst(args)
42
- }
43
- }
44
-
45
-
46
-
47
- module.exports = {
48
- Sync
1
+ try {
2
+ var bkp = require('./backup')
3
+ var rst = require('./restore')
4
+ } catch (e) {
5
+ console.log('Warning : Multi region sync not enabled.' )
6
+ }
7
+
8
+ class Sync {
9
+
10
+ loglevel = 1
11
+
12
+ constructor(){
13
+
14
+ }
15
+
16
+ async create(modelname, object) {
17
+ if (this.loglevel > 4)
18
+ console.log("Not implemented")
19
+ }
20
+
21
+ async insert(modelname, object) {
22
+ if (this.loglevel > 4)
23
+ console.log("Not implemented")
24
+ }
25
+
26
+ async update(modelname, filter, object) {
27
+ if (this.loglevel > 4)
28
+ console.log("Not implemented")
29
+ }
30
+
31
+ async delete(modelname, filter) {
32
+ if (this.loglevel > 4)
33
+ console.log("Not implemented")
34
+ }
35
+
36
+ backup(...args) {
37
+ bkp(args)
38
+ }
39
+
40
+ restore(...args) {
41
+ rst(args)
42
+ }
43
+ }
44
+
45
+
46
+
47
+ module.exports = {
48
+ Sync
49
49
  }
package/test/models.js CHANGED
@@ -1,23 +1,23 @@
1
- class Game {
2
-
3
- id;
4
- timeStamp;
5
- userid;
6
- amount;
7
- type;
8
-
9
- constructor(id,timeStamp,userid,amount,type){
10
- this.id=id
11
- this.userid=userid
12
- this.amount=amount
13
- this.type=type
14
- this.timeStamp=timeStamp
15
- }
16
-
17
- }
18
-
19
-
20
-
21
- module.exports = {
22
- Game
23
- };
1
+ class Game {
2
+
3
+ id;
4
+ timeStamp;
5
+ userid;
6
+ amount;
7
+ type;
8
+
9
+ constructor(id,timeStamp,userid,amount,type){
10
+ this.id=id
11
+ this.userid=userid
12
+ this.amount=amount
13
+ this.type=type
14
+ this.timeStamp=timeStamp
15
+ }
16
+
17
+ }
18
+
19
+
20
+
21
+ module.exports = {
22
+ Game
23
+ };