@nattyjs/orm 0.0.1-beta.21 → 0.0.1-beta.22

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/dist/index.cjs CHANGED
@@ -344,6 +344,29 @@ class SqlDbTransaction {
344
344
  }
345
345
  }
346
346
 
347
+ const connectionCacheContainer = new class {
348
+ getCacheKey(config) {
349
+ return `${config.server}-${config.database}`;
350
+ }
351
+ async getConnectionPool(mssql, config) {
352
+ return await new Promise((resolve, error) => {
353
+ const cacheKey = this.getCacheKey(config);
354
+ if (this.connectionPoolState[cacheKey])
355
+ return resolve(this.connectionPoolState[cacheKey]);
356
+ const pool = new mssql.ConnectionPool(config);
357
+ const errorHandler = (error2) => {
358
+ };
359
+ pool.on("error", errorHandler);
360
+ const connection = pool.connect((err) => {
361
+ if (err)
362
+ return error(err);
363
+ this.connectionPoolState[cacheKey] = connection;
364
+ resolve(connection);
365
+ });
366
+ });
367
+ }
368
+ }();
369
+
347
370
  class SqlConnection extends DbConnection {
348
371
  constructor(config) {
349
372
  super(config);
@@ -481,19 +504,7 @@ class SqlConnection extends DbConnection {
481
504
  return this.createPool();
482
505
  }
483
506
  async createPool() {
484
- return await new Promise((resolve, error) => {
485
- if (this.baseTransaction.transactionConnection)
486
- return resolve(this.baseTransaction.transactionConnection);
487
- const pool = new this.mssql.ConnectionPool(this.config);
488
- const errorHandler = (error2) => {
489
- };
490
- pool.on("error", errorHandler);
491
- const connection = pool.connect((err) => {
492
- if (err)
493
- return error(err);
494
- resolve(connection);
495
- });
496
- });
507
+ return await connectionCacheContainer.getConnectionPool(this.mssql, this.config);
497
508
  }
498
509
  }
499
510
 
package/dist/index.mjs CHANGED
@@ -328,6 +328,29 @@ class SqlDbTransaction {
328
328
  }
329
329
  }
330
330
 
331
+ const connectionCacheContainer = new class {
332
+ getCacheKey(config) {
333
+ return `${config.server}-${config.database}`;
334
+ }
335
+ async getConnectionPool(mssql, config) {
336
+ return await new Promise((resolve, error) => {
337
+ const cacheKey = this.getCacheKey(config);
338
+ if (this.connectionPoolState[cacheKey])
339
+ return resolve(this.connectionPoolState[cacheKey]);
340
+ const pool = new mssql.ConnectionPool(config);
341
+ const errorHandler = (error2) => {
342
+ };
343
+ pool.on("error", errorHandler);
344
+ const connection = pool.connect((err) => {
345
+ if (err)
346
+ return error(err);
347
+ this.connectionPoolState[cacheKey] = connection;
348
+ resolve(connection);
349
+ });
350
+ });
351
+ }
352
+ }();
353
+
331
354
  class SqlConnection extends DbConnection {
332
355
  constructor(config) {
333
356
  super(config);
@@ -465,19 +488,7 @@ class SqlConnection extends DbConnection {
465
488
  return this.createPool();
466
489
  }
467
490
  async createPool() {
468
- return await new Promise((resolve, error) => {
469
- if (this.baseTransaction.transactionConnection)
470
- return resolve(this.baseTransaction.transactionConnection);
471
- const pool = new this.mssql.ConnectionPool(this.config);
472
- const errorHandler = (error2) => {
473
- };
474
- pool.on("error", errorHandler);
475
- const connection = pool.connect((err) => {
476
- if (err)
477
- return error(err);
478
- resolve(connection);
479
- });
480
- });
491
+ return await connectionCacheContainer.getConnectionPool(this.mssql, this.config);
481
492
  }
482
493
  }
483
494
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/orm",
3
- "version": "0.0.1-beta.21",
3
+ "version": "0.0.1-beta.22",
4
4
  "description": "",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.cjs",
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "mssql": "^9.1.1",
21
- "@nattyjs/core": "0.0.1-beta.21",
22
- "@nattyjs/common": "0.0.1-beta.21",
23
- "@nattyjs/entity": "0.0.1-beta.21",
24
- "@nattyjs/types": "0.0.1-beta.21"
21
+ "@nattyjs/core": "0.0.1-beta.22",
22
+ "@nattyjs/common": "0.0.1-beta.22",
23
+ "@nattyjs/entity": "0.0.1-beta.22",
24
+ "@nattyjs/types": "0.0.1-beta.22"
25
25
  }
26
26
  }