@rsdk/db.knex 4.2.0-next.0 → 4.2.0-next.2
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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.2.0-next.2](https://github.com/R-Vision/rsdk/compare/v4.2.0-next.1...v4.2.0-next.2) (2024-02-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rsdk/db.knex
|
|
9
|
+
|
|
10
|
+
## [4.2.0-next.1](https://github.com/R-Vision/rsdk/compare/v4.2.0-next.0...v4.2.0-next.1) (2024-02-02)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* rework work with async context ([#201](https://github.com/R-Vision/rsdk/issues/201)) ([26de1a8](https://github.com/R-Vision/rsdk/commit/26de1a814692bcd082c2f1aaedad1215ec0df1a0))
|
|
15
|
+
|
|
6
16
|
## [4.2.0-next.0](https://github.com/R-Vision/rsdk/compare/v4.1.0...v4.2.0-next.0) (2024-02-02)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @rsdk/db.knex
|
|
@@ -6,8 +6,8 @@ export declare class KnexFactory implements OnApplicationShutdown {
|
|
|
6
6
|
private readonly appName;
|
|
7
7
|
private readonly logger;
|
|
8
8
|
private readonly config;
|
|
9
|
-
private static instance;
|
|
10
9
|
constructor(appName: string, logger: ILogger, config: KnexPluginConfig);
|
|
11
10
|
create(driver: string): Promise<Knex>;
|
|
12
11
|
onApplicationShutdown(): Promise<void>;
|
|
12
|
+
private instance;
|
|
13
13
|
}
|
|
@@ -11,7 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var KnexFactory_1;
|
|
15
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
15
|
exports.KnexFactory = void 0;
|
|
17
16
|
const common_1 = require("@nestjs/common");
|
|
@@ -21,21 +20,19 @@ const promises_1 = require("node:timers/promises");
|
|
|
21
20
|
const knex_config_1 = require("./knex.config");
|
|
22
21
|
const knex_logger_adapter_1 = require("./knex-logger.adapter");
|
|
23
22
|
let KnexFactory = class KnexFactory {
|
|
24
|
-
static { KnexFactory_1 = this; }
|
|
25
23
|
appName;
|
|
26
24
|
logger;
|
|
27
25
|
config;
|
|
28
|
-
static instance = null;
|
|
29
26
|
constructor(appName, logger, config) {
|
|
30
27
|
this.appName = appName;
|
|
31
28
|
this.logger = logger;
|
|
32
29
|
this.config = config;
|
|
33
30
|
}
|
|
34
31
|
async create(driver) {
|
|
35
|
-
if (
|
|
36
|
-
return
|
|
32
|
+
if (this.instance) {
|
|
33
|
+
return this.instance;
|
|
37
34
|
}
|
|
38
|
-
|
|
35
|
+
this.instance = (0, knex_1.knex)({
|
|
39
36
|
client: driver,
|
|
40
37
|
log: new knex_logger_adapter_1.KnexLoggerAdapter(this.logger),
|
|
41
38
|
connection: this.config.url.toString(),
|
|
@@ -71,7 +68,7 @@ let KnexFactory = class KnexFactory {
|
|
|
71
68
|
let attempt = 1;
|
|
72
69
|
while (attempt < this.config.reconnectAttempts) {
|
|
73
70
|
try {
|
|
74
|
-
await
|
|
71
|
+
await this.instance.raw('SELECT 1');
|
|
75
72
|
break;
|
|
76
73
|
}
|
|
77
74
|
catch (error) {
|
|
@@ -79,16 +76,17 @@ let KnexFactory = class KnexFactory {
|
|
|
79
76
|
await (0, promises_1.setTimeout)(this.config.reconnectInterval.millis());
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
|
-
return
|
|
79
|
+
return this.instance;
|
|
83
80
|
}
|
|
84
81
|
async onApplicationShutdown() {
|
|
85
|
-
if (
|
|
86
|
-
await
|
|
82
|
+
if (this.instance) {
|
|
83
|
+
await this.instance.destroy();
|
|
87
84
|
}
|
|
88
85
|
}
|
|
86
|
+
instance = null;
|
|
89
87
|
};
|
|
90
88
|
exports.KnexFactory = KnexFactory;
|
|
91
|
-
exports.KnexFactory = KnexFactory =
|
|
89
|
+
exports.KnexFactory = KnexFactory = __decorate([
|
|
92
90
|
(0, common_1.Injectable)(),
|
|
93
91
|
__param(0, (0, core_1.AppName)()),
|
|
94
92
|
__param(1, (0, core_1.InjectLogger)(KnexFactory)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knex.factory.js","sourceRoot":"","sources":["../../src/providers/knex.factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"knex.factory.js","sourceRoot":"","sources":["../../src/providers/knex.factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAA4C;AAC5C,qCAAmD;AAGnD,+BAA4B;AAC5B,mDAAkD;AAElD,+CAAiD;AACjD,+DAA0D;AAGnD,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEQ;IACgB;IAC3B;IAHnB,YAC8B,OAAe,EACC,MAAe,EAC1C,MAAwB;QAFb,YAAO,GAAP,OAAO,CAAQ;QACC,WAAM,GAAN,MAAM,CAAS;QAC1C,WAAM,GAAN,MAAM,CAAkB;IACxC,CAAC;IAEG,KAAK,CAAC,MAAM,CAAC,MAAc;QAChC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAA,WAAI,EAAC;YACnB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,IAAI,uCAAiB,CAAC,IAAI,CAAC,MAAM,CAAC;YACvC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;YACtC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI;gBACxB,UAAU,EA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C,CAAA;AAtEY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,cAAO,GAAE,CAAA;IACT,WAAA,IAAA,mBAAY,EAAC,WAAW,CAAC,CAAA;qDACD,8BAAgB;GAJhC,WAAW,CAsEvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/db.knex",
|
|
3
|
-
"version": "4.2.0-next.
|
|
3
|
+
"version": "4.2.0-next.2",
|
|
4
4
|
"description": "Knex integration for platform",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@nestjs/common": "^10.0.0",
|
|
18
18
|
"@nestjs/core": "^10.0.0",
|
|
19
|
-
"@rsdk/common": "^4.2.0-next.
|
|
20
|
-
"@rsdk/common.node": "^4.2.0-next.
|
|
21
|
-
"@rsdk/core": "^4.2.0-next.
|
|
22
|
-
"@rsdk/db": "^4.2.0-next.
|
|
23
|
-
"@rsdk/logging": "^4.2.0-next.
|
|
19
|
+
"@rsdk/common": "^4.2.0-next.2",
|
|
20
|
+
"@rsdk/common.node": "^4.2.0-next.2",
|
|
21
|
+
"@rsdk/core": "^4.2.0-next.2",
|
|
22
|
+
"@rsdk/db": "^4.2.0-next.2",
|
|
23
|
+
"@rsdk/logging": "^4.2.0-next.2",
|
|
24
24
|
"knex": "^2.4.2",
|
|
25
25
|
"reflect-metadata": "^0.1.13",
|
|
26
26
|
"rxjs": "^7.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "acdde40b104a70d66b99ec9f6e04236d484edeff"
|
|
29
29
|
}
|
|
@@ -11,8 +11,6 @@ import { KnexLoggerAdapter } from './knex-logger.adapter';
|
|
|
11
11
|
|
|
12
12
|
@Injectable()
|
|
13
13
|
export class KnexFactory implements OnApplicationShutdown {
|
|
14
|
-
private static instance: Knex | null = null;
|
|
15
|
-
|
|
16
14
|
constructor(
|
|
17
15
|
@AppName() private readonly appName: string,
|
|
18
16
|
@InjectLogger(KnexFactory) private readonly logger: ILogger,
|
|
@@ -20,11 +18,11 @@ export class KnexFactory implements OnApplicationShutdown {
|
|
|
20
18
|
) {}
|
|
21
19
|
|
|
22
20
|
public async create(driver: string): Promise<Knex> {
|
|
23
|
-
if (
|
|
24
|
-
return
|
|
21
|
+
if (this.instance) {
|
|
22
|
+
return this.instance;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
this.instance = knex({
|
|
28
26
|
client: driver,
|
|
29
27
|
log: new KnexLoggerAdapter(this.logger),
|
|
30
28
|
connection: this.config.url.toString(),
|
|
@@ -64,7 +62,7 @@ export class KnexFactory implements OnApplicationShutdown {
|
|
|
64
62
|
|
|
65
63
|
while (attempt < this.config.reconnectAttempts) {
|
|
66
64
|
try {
|
|
67
|
-
await
|
|
65
|
+
await this.instance.raw('SELECT 1');
|
|
68
66
|
break;
|
|
69
67
|
} catch (error) {
|
|
70
68
|
this.logger.error(`try: ${attempt++} - not connected`, error as Error);
|
|
@@ -72,12 +70,14 @@ export class KnexFactory implements OnApplicationShutdown {
|
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
return
|
|
73
|
+
return this.instance;
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
public async onApplicationShutdown(): Promise<void> {
|
|
79
|
-
if (
|
|
80
|
-
await
|
|
77
|
+
if (this.instance) {
|
|
78
|
+
await this.instance.destroy();
|
|
81
79
|
}
|
|
82
80
|
}
|
|
81
|
+
|
|
82
|
+
private instance: Knex | null = null;
|
|
83
83
|
}
|