multi-db-orm 3.0.12 → 3.1.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,68 +1,73 @@
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
- async connect() {
20
-
21
- }
22
-
23
- setdb(db) {
24
- this.reqMade = 0
25
- this.db = db;
26
- }
27
-
28
- getdb() {
29
- this.reqMade++
30
- return this.db;
31
- }
32
-
33
- async get(modelname, filter) {
34
- if (this.loglevel > 4)
35
- console.log("Not implemented")
36
- }
37
-
38
- async getOne(modelname, filter) {
39
- if (this.loglevel > 4)
40
- console.log("Not implemented")
41
- }
42
-
43
- async create(modelname, object) {
44
- if (this.loglevel > 4)
45
- console.log("Not implemented")
46
- }
47
-
48
- async insert(modelname, object) {
49
- if (this.loglevel > 4)
50
- console.log("Not implemented")
51
- }
52
-
53
- async update(modelname, filter, object) {
54
- if (this.loglevel > 4)
55
- console.log("Not implemented")
56
- }
57
-
58
- async delete(modelname, filter) {
59
- if (this.loglevel > 4)
60
- console.log("Not implemented")
61
- }
62
-
63
- }
64
-
65
-
66
- module.exports = {
67
- 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
+ setLogLevel(level) {
20
+ this.loglevel = level;
21
+ this.metrics.setLogLevel(level);
22
+ }
23
+
24
+ async connect() {
25
+
26
+ }
27
+
28
+ setdb(db) {
29
+ this.reqMade = 0
30
+ this.db = db;
31
+ }
32
+
33
+ getdb() {
34
+ this.reqMade++
35
+ return this.db;
36
+ }
37
+
38
+ async get(modelname, filter) {
39
+ if (this.loglevel > 4)
40
+ console.log("Not implemented")
41
+ }
42
+
43
+ async getOne(modelname, filter) {
44
+ if (this.loglevel > 4)
45
+ console.log("Not implemented")
46
+ }
47
+
48
+ async create(modelname, object) {
49
+ if (this.loglevel > 4)
50
+ console.log("Not implemented")
51
+ }
52
+
53
+ async insert(modelname, object) {
54
+ if (this.loglevel > 4)
55
+ console.log("Not implemented")
56
+ }
57
+
58
+ async update(modelname, filter, object) {
59
+ if (this.loglevel > 4)
60
+ console.log("Not implemented")
61
+ }
62
+
63
+ async delete(modelname, filter) {
64
+ if (this.loglevel > 4)
65
+ console.log("Not implemented")
66
+ }
67
+
68
+ }
69
+
70
+
71
+ module.exports = {
72
+ MultiDbORM: MultiDbORM
68
73
  }
@@ -1,25 +1,25 @@
1
- import { MultiDbORM } from './multidb';
2
-
3
- export type MySQLDBConfig = {
4
- host: string;
5
- port: string;
6
- username: string;
7
- password: string;
8
- database: string;
9
- connectionLimit?: Number;
10
- connectTimeout?: Number;
11
- acquireTimeout?: Number;
12
- timeout?: Number;
13
- }
14
-
15
- export class MySQLDB extends MultiDbORM {
16
- db: typeof import('mysql')
17
- mysql: typeof import('mysql');
18
- connection: import('mysql').Connection;
19
-
20
- constructor(credentials: MySQLDBConfig);
21
-
22
- run(query: string): Promise<any[]>;
23
-
24
- closePool(): void;
25
- }
1
+ import { MultiDbORM } from './multidb';
2
+
3
+ export type MySQLDBConfig = {
4
+ host: string;
5
+ port: string;
6
+ username: string;
7
+ password: string;
8
+ database: string;
9
+ connectionLimit?: Number;
10
+ connectTimeout?: Number;
11
+ acquireTimeout?: Number;
12
+ timeout?: Number;
13
+ }
14
+
15
+ export class MySQLDB extends MultiDbORM {
16
+ db: typeof import('mysql')
17
+ mysql: typeof import('mysql');
18
+ connection: import('mysql').Connection;
19
+
20
+ constructor(credentials: MySQLDBConfig);
21
+
22
+ run(query: string): Promise<any[]>;
23
+
24
+ closePool(): void;
25
+ }
@@ -64,7 +64,7 @@ class MySQLDB extends MultiDbORM {
64
64
  }
65
65
 
66
66
  async get(modelname, filter, options) {
67
- this.metrics.get(modelname, filter, options);
67
+ const span = this.metrics.getSpan();
68
68
  var where = "";
69
69
  for (var key in filter) {
70
70
  where = where + `${key} = '${filter[key]}' AND `;
@@ -100,11 +100,13 @@ class MySQLDB extends MultiDbORM {
100
100
  offset = `OFFSET ${options.offset}`;
101
101
  }
102
102
  var query = `SELECT * FROM ${modelname} WHERE ${where} ${sort} ${limit} ${offset};`;
103
- return (await this.run(query)) || [];
103
+ const res = (await this.run(query)) || [];
104
+ this.metrics.get(modelname, filter, options, span);
105
+ return res;
104
106
  }
105
107
 
106
108
  async getOne(modelname, filter) {
107
- this.metrics.getOne(modelname, filter);
109
+ const span = this.metrics.getOneSpan();
108
110
  var where = "";
109
111
  for (var key in filter) {
110
112
  where = where + `${key} = '${filter[key]}' AND `;
@@ -112,11 +114,12 @@ class MySQLDB extends MultiDbORM {
112
114
  where = where + " 1 ";
113
115
  var query = `SELECT * FROM ${modelname} WHERE ${where} LIMIT 1;`;
114
116
  var row = await this.run(query);
117
+ this.metrics.getOne(modelname, filter, span);
115
118
  return row[0];
116
119
  }
117
120
  async create(modelname, sampleObject) {
118
121
  this.sync.create(modelname, sampleObject);
119
- this.metrics.create(modelname, sampleObject);
122
+ const span = this.metrics.createSpan();
120
123
 
121
124
  var cols = "";
122
125
  for (var key in sampleObject) {
@@ -144,7 +147,9 @@ class MySQLDB extends MultiDbORM {
144
147
  cols = cols.substring(0, cols.length - 1);
145
148
  var query = `CREATE TABLE IF NOT EXISTS ${modelname} (${cols});`;
146
149
  try {
147
- return await this.run(query);
150
+ const res = await this.run(query);
151
+ this.metrics.create(modelname, sampleObject, span);
152
+ return res;
148
153
  } catch (err) {
149
154
  if (this.loglevel > 0) console.log(err);
150
155
  throw err;
@@ -153,7 +158,7 @@ class MySQLDB extends MultiDbORM {
153
158
 
154
159
  async insert(modelname, object) {
155
160
  this.sync.insert(modelname, object);
156
- this.metrics.insert(modelname, object);
161
+ const span = this.metrics.insertSpan();
157
162
  var cols = "";
158
163
  var vals = "";
159
164
  for (var key in object) {
@@ -171,11 +176,15 @@ class MySQLDB extends MultiDbORM {
171
176
  var query = `INSERT INTO ${modelname} (${cols}) VALUES(${vals});`;
172
177
 
173
178
  try {
174
- return await this.run(query);
179
+ const res = await this.run(query);
180
+ this.metrics.insert(modelname, object, span);
181
+ return res;
175
182
  } catch (err) {
176
183
  if (err.code && err.code === "ER_NO_SUCH_TABLE") {
177
184
  await this.create(modelname, object);
178
- return await this.run(query);
185
+ const res = await this.run(query);
186
+ this.metrics.insert(modelname, object, span);
187
+ return res;
179
188
  } else {
180
189
  throw err;
181
190
  }
@@ -184,7 +193,7 @@ class MySQLDB extends MultiDbORM {
184
193
 
185
194
  async update(modelname, filter, object) {
186
195
  this.sync.update(modelname, filter, object);
187
- this.metrics.update(modelname, filter, object);
196
+ const span = this.metrics.updateSpan();
188
197
 
189
198
  var where = "";
190
199
  var vals = "";
@@ -212,7 +221,9 @@ class MySQLDB extends MultiDbORM {
212
221
 
213
222
  var query = `UPDATE ${modelname} SET ${vals} WHERE ${where};`;
214
223
  try {
215
- return await this.run(query);
224
+ const res = await this.run(query);
225
+ this.metrics.update(modelname, filter, object, span);
226
+ return res;
216
227
  } catch (e) {
217
228
  if (this.loglevel > 4) console.log("Error in update", e);
218
229
  throw e;
@@ -221,7 +232,7 @@ class MySQLDB extends MultiDbORM {
221
232
 
222
233
  async delete(modelname, filter) {
223
234
  this.sync.delete(modelname, filter);
224
- this.metrics.delete(modelname, filter);
235
+ const span = this.metrics.deleteSpan();
225
236
 
226
237
  var where = "";
227
238
  for (var key in filter) {
@@ -229,7 +240,9 @@ class MySQLDB extends MultiDbORM {
229
240
  }
230
241
  where = where + " 1 ";
231
242
  var query = `DELETE FROM ${modelname} WHERE ${where};`;
232
- return await this.run(query);
243
+ const res = await this.run(query);
244
+ this.metrics.delete(modelname, filter, span);
245
+ return res;
233
246
  }
234
247
 
235
248
  closePool() {
@@ -1,24 +1,24 @@
1
- import { MultiDbORM } from './multidb';
2
-
3
- export interface OracleDBConfig {
4
- username: string;
5
- password: string;
6
- net_service_name: string;
7
- wallet_dir: string;
8
- connection_pool_name?: string;
9
- wallet_password?: string;
10
- lib_dir?: string;
11
- }
12
-
13
- export declare class OracleDB extends MultiDbORM {
14
- db: typeof import('oracledb')
15
- connection_pool_name: string;
16
- schema: string;
17
- pool_creation: Promise<any>;
18
-
19
- constructor(config: OracleDBConfig);
20
-
21
- connect(): Promise<void>;
22
-
23
- run(query: string): Promise<any>;
24
- }
1
+ import { MultiDbORM } from './multidb';
2
+
3
+ export interface OracleDBConfig {
4
+ username: string;
5
+ password: string;
6
+ net_service_name: string;
7
+ wallet_dir: string;
8
+ connection_pool_name?: string;
9
+ wallet_password?: string;
10
+ lib_dir?: string;
11
+ }
12
+
13
+ export declare class OracleDB extends MultiDbORM {
14
+ db: typeof import('oracledb')
15
+ connection_pool_name: string;
16
+ schema: string;
17
+ pool_creation: Promise<any>;
18
+
19
+ constructor(config: OracleDBConfig);
20
+
21
+ connect(): Promise<void>;
22
+
23
+ run(query: string): Promise<any>;
24
+ }