multi-db-orm 1.2.3 → 1.3.1

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.
@@ -1,149 +1,149 @@
1
- const { MultiDbORM } = require("./multidb");
2
-
3
- class MongoDB extends MultiDbORM {
4
-
5
- mongodbname
6
- dbc
7
- client
8
- url
9
- constructor(secureUrl, mongodbname) {
10
- super()
11
-
12
- this.url = secureUrl;
13
- this.mongodbname = mongodbname
14
-
15
- const MongoClient = require('mongodb').MongoClient;
16
- this.client = new MongoClient(this.url, {
17
- useUnifiedTopology: true,
18
- useNewUrlParser: true
19
- });
20
- this._connect();
21
- }
22
-
23
- async _close() {
24
- this.dbc.close();
25
- }
26
-
27
- async _connect() {
28
- var dbc = await this.client.connect();
29
- this.dbc = dbc;
30
- this.db = dbc.db(this.mongodbname);
31
- console.log("MongoDB Initialized");
32
- this.dbType = 'mongodb'
33
- }
34
-
35
- async run(query) {
36
- if (this.loglevel > 3)
37
- console.log('RUN : Not Supported in DB Type', this.dbType)
38
- }
39
- _inq2mongop(symbol) {
40
- switch (symbol) {
41
- case "=":
42
- return "$eq";
43
- case ">":
44
- return "$gt";
45
- case ">=":
46
- return "$gte";
47
- case "<":
48
- return "$lt";
49
- case "<=":
50
- return "$lte";
51
- case "!=":
52
- return "$ne";
53
- }
54
- }
55
- async get(modelname, filter, options) {
56
- this.metrics.get(modelname, filter, options);
57
- if (options && options.apply && options.apply.ineq) {
58
- filter[`${options.apply.field}`] = {};
59
- filter[`${options.apply.field}`][`${this._inq2mongop(options.apply.ineq.op)}`] = options.apply.ineq.value
60
- }
61
- var crs = this.getdb().collection(modelname).find(filter);
62
- if (options) {
63
- if (options.apply) {
64
- if (options.apply.sort) {
65
- var order = 1;
66
- if (options.apply.sort == 'desc') {
67
- order = -1;
68
- }
69
- var sortOption = {};
70
- sortOption[`${options.apply.field}`] = order;
71
- crs = crs.sort(sortOption);
72
- }
73
-
74
- } else if (options.sort) {
75
-
76
- var sortOption = {};
77
- options.sort.forEach(srt => {
78
- var order = 1;
79
- if (srt.order == 'desc') {
80
- order = -1;
81
- }
82
- sortOption[`${srt.field}`] = order;
83
- });
84
- crs = crs.sort(sortOption);
85
- }
86
-
87
- if (options.limit) {
88
- crs.limit(options.limit)
89
- }
90
-
91
- if (options.offset) {
92
- crs.skip(options.offset)
93
- }
94
- }
95
-
96
- var snapshot = await crs.toArray()
97
- return snapshot;
98
-
99
- }
100
-
101
- async getOne(modelname, filter, options) {
102
- this.metrics.getOne(modelname, filter, options);
103
- var snapshot = await this.getdb().collection(modelname).findOne(filter)
104
- return snapshot;
105
- }
106
-
107
- async create(modelname, sampleObject) {
108
- this.sync.create(modelname, sampleObject)
109
- this.metrics.create(modelname, sampleObject);
110
-
111
- if (this.loglevel > 3)
112
- console.log('CREATE : Not required in DB Type', this.dbType)
113
- }
114
-
115
- async insert(modelname, object) {
116
- this.sync.insert(modelname, object)
117
- this.metrics.insert(modelname, object)
118
-
119
- const collref = this.getdb().collection(modelname)
120
- try {
121
- return await collref.insertOne(object);
122
- } catch (e) {
123
-
124
- throw e;
125
-
126
- }
127
-
128
- }
129
-
130
- async update(modelname, filter, object) {
131
- this.sync.update(modelname, filter, object)
132
- this.metrics.update(modelname, filter, object)
133
- var resp = await this.getdb().collection(modelname).updateMany(filter, { $set: object })
134
- return resp;
135
- }
136
-
137
- async delete(modelname, filter) {
138
- this.sync.delete(modelname, filter)
139
- this.metrics.delete(modelname, filter)
140
- var resp = await this.getdb().collection(modelname).deleteMany(filter)
141
- return resp;
142
- }
143
- }
144
-
145
-
146
-
147
- module.exports = {
148
- MongoDB
1
+ const { MultiDbORM } = require("./multidb");
2
+
3
+ class MongoDB extends MultiDbORM {
4
+
5
+ mongodbname
6
+ dbc
7
+ client
8
+ url
9
+ constructor(secureUrl, mongodbname) {
10
+ super()
11
+
12
+ this.url = secureUrl;
13
+ this.mongodbname = mongodbname
14
+
15
+ const MongoClient = require('mongodb').MongoClient;
16
+ this.client = new MongoClient(this.url, {
17
+ useUnifiedTopology: true,
18
+ useNewUrlParser: true
19
+ });
20
+ this._connect();
21
+ }
22
+
23
+ async _close() {
24
+ this.dbc.close();
25
+ }
26
+
27
+ async _connect() {
28
+ var dbc = await this.client.connect();
29
+ this.dbc = dbc;
30
+ this.db = dbc.db(this.mongodbname);
31
+ console.log("MongoDB Initialized");
32
+ this.dbType = 'mongodb'
33
+ }
34
+
35
+ async run(query) {
36
+ if (this.loglevel > 3)
37
+ console.log('RUN : Not Supported in DB Type', this.dbType)
38
+ }
39
+ _inq2mongop(symbol) {
40
+ switch (symbol) {
41
+ case "=":
42
+ return "$eq";
43
+ case ">":
44
+ return "$gt";
45
+ case ">=":
46
+ return "$gte";
47
+ case "<":
48
+ return "$lt";
49
+ case "<=":
50
+ return "$lte";
51
+ case "!=":
52
+ return "$ne";
53
+ }
54
+ }
55
+ async get(modelname, filter, options) {
56
+ this.metrics.get(modelname, filter, options);
57
+ if (options && options.apply && options.apply.ineq) {
58
+ filter[`${options.apply.field}`] = {};
59
+ filter[`${options.apply.field}`][`${this._inq2mongop(options.apply.ineq.op)}`] = options.apply.ineq.value
60
+ }
61
+ var crs = this.getdb().collection(modelname).find(filter);
62
+ if (options) {
63
+ if (options.apply) {
64
+ if (options.apply.sort) {
65
+ var order = 1;
66
+ if (options.apply.sort == 'desc') {
67
+ order = -1;
68
+ }
69
+ var sortOption = {};
70
+ sortOption[`${options.apply.field}`] = order;
71
+ crs = crs.sort(sortOption);
72
+ }
73
+
74
+ } else if (options.sort) {
75
+
76
+ var sortOption = {};
77
+ options.sort.forEach(srt => {
78
+ var order = 1;
79
+ if (srt.order == 'desc') {
80
+ order = -1;
81
+ }
82
+ sortOption[`${srt.field}`] = order;
83
+ });
84
+ crs = crs.sort(sortOption);
85
+ }
86
+
87
+ if (options.limit) {
88
+ crs.limit(options.limit)
89
+ }
90
+
91
+ if (options.offset) {
92
+ crs.skip(options.offset)
93
+ }
94
+ }
95
+
96
+ var snapshot = await crs.toArray()
97
+ return snapshot;
98
+
99
+ }
100
+
101
+ async getOne(modelname, filter, options) {
102
+ this.metrics.getOne(modelname, filter, options);
103
+ var snapshot = await this.getdb().collection(modelname).findOne(filter)
104
+ return snapshot;
105
+ }
106
+
107
+ async create(modelname, sampleObject) {
108
+ this.sync.create(modelname, sampleObject)
109
+ this.metrics.create(modelname, sampleObject);
110
+
111
+ if (this.loglevel > 3)
112
+ console.log('CREATE : Not required in DB Type', this.dbType)
113
+ }
114
+
115
+ async insert(modelname, object) {
116
+ this.sync.insert(modelname, object)
117
+ this.metrics.insert(modelname, object)
118
+
119
+ const collref = this.getdb().collection(modelname)
120
+ try {
121
+ return await collref.insertOne(object);
122
+ } catch (e) {
123
+
124
+ throw e;
125
+
126
+ }
127
+
128
+ }
129
+
130
+ async update(modelname, filter, object) {
131
+ this.sync.update(modelname, filter, object)
132
+ this.metrics.update(modelname, filter, object)
133
+ var resp = await this.getdb().collection(modelname).updateMany(filter, { $set: object })
134
+ return resp;
135
+ }
136
+
137
+ async delete(modelname, filter) {
138
+ this.sync.delete(modelname, filter)
139
+ this.metrics.delete(modelname, filter)
140
+ var resp = await this.getdb().collection(modelname).deleteMany(filter)
141
+ return resp;
142
+ }
143
+ }
144
+
145
+
146
+
147
+ module.exports = {
148
+ MongoDB
149
149
  }
@@ -1,64 +1,64 @@
1
- const {Sync} = require('../sync')
2
- const { Metrics } = require('./metrics')
3
- class MultiDbORM {
4
-
5
- db
6
- dbType
7
- reqMade
8
- lastQLatency
9
- loglevel = 0
10
- sync
11
- metrics
12
-
13
- constructor(db) {
14
- this.db = db
15
- this.sync = new Sync()
16
- this.metrics = new Metrics(this.loglevel)
17
- }
18
-
19
- setdb(db) {
20
- this.reqMade = 0
21
- this.db = db;
22
- }
23
-
24
- getdb() {
25
- this.reqMade++
26
- return this.db;
27
- }
28
-
29
- async get(modelname, filter) {
30
- if (this.loglevel > 4)
31
- console.log("Not implemented")
32
- }
33
-
34
- async getOne(modelname, filter) {
35
- if (this.loglevel > 4)
36
- console.log("Not implemented")
37
- }
38
-
39
- async create(modelname, object) {
40
- if (this.loglevel > 4)
41
- console.log("Not implemented")
42
- }
43
-
44
- async insert(modelname, object) {
45
- if (this.loglevel > 4)
46
- console.log("Not implemented")
47
- }
48
-
49
- async update(modelname, filter, object) {
50
- if (this.loglevel > 4)
51
- console.log("Not implemented")
52
- }
53
-
54
- async delete(modelname, filter) {
55
- if (this.loglevel > 4)
56
- console.log("Not implemented")
57
- }
58
-
59
- }
60
-
61
-
62
- module.exports = {
63
- MultiDbORM: MultiDbORM
1
+ const {Sync} = require('../sync')
2
+ const { Metrics } = require('./metrics')
3
+ class MultiDbORM {
4
+
5
+ db
6
+ dbType
7
+ reqMade
8
+ lastQLatency
9
+ loglevel = 0
10
+ sync
11
+ metrics
12
+
13
+ constructor(db) {
14
+ this.db = db
15
+ this.sync = new Sync()
16
+ this.metrics = new Metrics(this.loglevel)
17
+ }
18
+
19
+ setdb(db) {
20
+ this.reqMade = 0
21
+ this.db = db;
22
+ }
23
+
24
+ getdb() {
25
+ this.reqMade++
26
+ return this.db;
27
+ }
28
+
29
+ async get(modelname, filter) {
30
+ if (this.loglevel > 4)
31
+ console.log("Not implemented")
32
+ }
33
+
34
+ async getOne(modelname, filter) {
35
+ if (this.loglevel > 4)
36
+ console.log("Not implemented")
37
+ }
38
+
39
+ async create(modelname, object) {
40
+ if (this.loglevel > 4)
41
+ console.log("Not implemented")
42
+ }
43
+
44
+ async insert(modelname, object) {
45
+ if (this.loglevel > 4)
46
+ console.log("Not implemented")
47
+ }
48
+
49
+ async update(modelname, filter, object) {
50
+ if (this.loglevel > 4)
51
+ console.log("Not implemented")
52
+ }
53
+
54
+ async delete(modelname, filter) {
55
+ if (this.loglevel > 4)
56
+ console.log("Not implemented")
57
+ }
58
+
59
+ }
60
+
61
+
62
+ module.exports = {
63
+ MultiDbORM: MultiDbORM
64
64
  }