@nattyjs/orm 0.0.1-beta.21 → 0.0.1-beta.23
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 +27 -13
- package/dist/index.mjs +27 -13
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -344,6 +344,32 @@ class SqlDbTransaction {
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
+
const connectionCacheContainer = new class {
|
|
348
|
+
constructor() {
|
|
349
|
+
this.connectionPoolState = {};
|
|
350
|
+
}
|
|
351
|
+
getCacheKey(config) {
|
|
352
|
+
return `${config.server}-${config.database}`;
|
|
353
|
+
}
|
|
354
|
+
async getConnectionPool(mssql, config) {
|
|
355
|
+
return await new Promise((resolve, error) => {
|
|
356
|
+
const cacheKey = this.getCacheKey(config);
|
|
357
|
+
if (this.connectionPoolState[cacheKey])
|
|
358
|
+
return resolve(this.connectionPoolState[cacheKey]);
|
|
359
|
+
const pool = new mssql.ConnectionPool(config);
|
|
360
|
+
const errorHandler = (error2) => {
|
|
361
|
+
};
|
|
362
|
+
pool.on("error", errorHandler);
|
|
363
|
+
const connection = pool.connect((err) => {
|
|
364
|
+
if (err)
|
|
365
|
+
return error(err);
|
|
366
|
+
this.connectionPoolState[cacheKey] = connection;
|
|
367
|
+
resolve(connection);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}();
|
|
372
|
+
|
|
347
373
|
class SqlConnection extends DbConnection {
|
|
348
374
|
constructor(config) {
|
|
349
375
|
super(config);
|
|
@@ -481,19 +507,7 @@ class SqlConnection extends DbConnection {
|
|
|
481
507
|
return this.createPool();
|
|
482
508
|
}
|
|
483
509
|
async createPool() {
|
|
484
|
-
return await
|
|
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
|
-
});
|
|
510
|
+
return await connectionCacheContainer.getConnectionPool(this.mssql, this.config);
|
|
497
511
|
}
|
|
498
512
|
}
|
|
499
513
|
|
package/dist/index.mjs
CHANGED
|
@@ -328,6 +328,32 @@ class SqlDbTransaction {
|
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
+
const connectionCacheContainer = new class {
|
|
332
|
+
constructor() {
|
|
333
|
+
this.connectionPoolState = {};
|
|
334
|
+
}
|
|
335
|
+
getCacheKey(config) {
|
|
336
|
+
return `${config.server}-${config.database}`;
|
|
337
|
+
}
|
|
338
|
+
async getConnectionPool(mssql, config) {
|
|
339
|
+
return await new Promise((resolve, error) => {
|
|
340
|
+
const cacheKey = this.getCacheKey(config);
|
|
341
|
+
if (this.connectionPoolState[cacheKey])
|
|
342
|
+
return resolve(this.connectionPoolState[cacheKey]);
|
|
343
|
+
const pool = new mssql.ConnectionPool(config);
|
|
344
|
+
const errorHandler = (error2) => {
|
|
345
|
+
};
|
|
346
|
+
pool.on("error", errorHandler);
|
|
347
|
+
const connection = pool.connect((err) => {
|
|
348
|
+
if (err)
|
|
349
|
+
return error(err);
|
|
350
|
+
this.connectionPoolState[cacheKey] = connection;
|
|
351
|
+
resolve(connection);
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}();
|
|
356
|
+
|
|
331
357
|
class SqlConnection extends DbConnection {
|
|
332
358
|
constructor(config) {
|
|
333
359
|
super(config);
|
|
@@ -465,19 +491,7 @@ class SqlConnection extends DbConnection {
|
|
|
465
491
|
return this.createPool();
|
|
466
492
|
}
|
|
467
493
|
async createPool() {
|
|
468
|
-
return await
|
|
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
|
-
});
|
|
494
|
+
return await connectionCacheContainer.getConnectionPool(this.mssql, this.config);
|
|
481
495
|
}
|
|
482
496
|
}
|
|
483
497
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nattyjs/orm",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.23",
|
|
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.
|
|
22
|
-
"@nattyjs/common": "0.0.1-beta.
|
|
23
|
-
"@nattyjs/entity": "0.0.1-beta.
|
|
24
|
-
"@nattyjs/types": "0.0.1-beta.
|
|
21
|
+
"@nattyjs/core": "0.0.1-beta.23",
|
|
22
|
+
"@nattyjs/common": "0.0.1-beta.23",
|
|
23
|
+
"@nattyjs/entity": "0.0.1-beta.23",
|
|
24
|
+
"@nattyjs/types": "0.0.1-beta.23"
|
|
25
25
|
}
|
|
26
26
|
}
|