@sqb/nestjs 4.21.0 → 4.21.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.
- package/README.md +33 -0
- package/package.json +3 -3
- package/sqb-core.module.d.ts +4 -2
- package/sqb-core.module.js +30 -3
- package/sqb.interface.d.ts +1 -0
package/README.md
CHANGED
|
@@ -41,6 +41,38 @@ $ npm install @sqb/nestjs --save
|
|
|
41
41
|
|
|
42
42
|
- node >= 16.x
|
|
43
43
|
|
|
44
|
+
## Environment Variables
|
|
45
|
+
|
|
46
|
+
The library supports configuration through environment variables. Environment variables below is accepted.
|
|
47
|
+
All environment variables starts with prefix (SQB\_). This can be configured while registering the module.
|
|
48
|
+
|
|
49
|
+
<!--- BEGIN env --->
|
|
50
|
+
|
|
51
|
+
| Environment Variable | Type | Default | Description |
|
|
52
|
+
|------------------------------|---------|---------|-------------------------------------------------------|
|
|
53
|
+
| SQB_DIALECT | String | | Database dialect (e.g. postgres, mysql, oracle) |
|
|
54
|
+
| SQB_CONNECTION_NAME | String | | Logical name of the database connection |
|
|
55
|
+
| SQB_HOST | String | | Database server host address |
|
|
56
|
+
| SQB_PORT | Number | | Database server port |
|
|
57
|
+
| SQB_DATABASE | String | | Database name |
|
|
58
|
+
| SQB_SCHEMA | String | | Default database schema |
|
|
59
|
+
| SQB_USER | String | | Database user name |
|
|
60
|
+
| SQB_PASSWORD | String | | Database user password |
|
|
61
|
+
| SQB_DRIVER | String | | Database driver identifier |
|
|
62
|
+
| SQB_POOL_MAX | Number | | Maximum number of connections in the pool |
|
|
63
|
+
| SQB_POOL_MIN | Number | | Minimum number of connections in the pool |
|
|
64
|
+
| SQB_POOL_IDLE_TIMEOUT | Number | | Time (ms) before an idle connection is released |
|
|
65
|
+
| SQB_POOL_ACQUIRE_TIMEOUT | Number | | Timeout (ms) for acquiring a connection |
|
|
66
|
+
| SQB_POOL_ACQUIRE_MAX_RETRIES | Number | | Maximum number of retries when acquiring a connection |
|
|
67
|
+
| SQB_POOL_ACQUIRE_RETRY_WAIT | Number | | Wait time (ms) between acquire retry attempts |
|
|
68
|
+
| SQB_POOL_FIFO | Boolean | | Whether the pool queue operates in FIFO mode |
|
|
69
|
+
| SQB_POOL_MAX_QUEUE | Number | | Maximum number of queued connection requests |
|
|
70
|
+
| SQB_POOL_MIN_IDLE | Number | | Minimum number of idle connections to keep |
|
|
71
|
+
| SQB_POOL_VALIDATION | Boolean | | Enables validation of connections before use |
|
|
72
|
+
| SQB_POOL_HOUSE_KEEP_INTERVAL | Number | | Interval (ms) for pool housekeeping tasks |
|
|
73
|
+
|
|
74
|
+
<!--- END env --->
|
|
75
|
+
|
|
44
76
|
### License
|
|
45
77
|
|
|
46
78
|
SQB is available under [MIT](LICENSE) license.
|
|
@@ -61,3 +93,4 @@ SQB is available under [MIT](LICENSE) license.
|
|
|
61
93
|
[devdependencies-url]: https://david-dm.org/sqbjs/@sqb/nestjs?type=dev
|
|
62
94
|
[quality-image]: http://npm.packagequality.com/shield/@sqb/nestjs.png
|
|
63
95
|
[quality-url]: http://packagequality.com/#?package=@sqb/nestjs
|
|
96
|
+
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/nestjs",
|
|
3
3
|
"description": "Nestjs module for data connection using SQB",
|
|
4
|
-
"version": "4.21.
|
|
4
|
+
"version": "4.21.1",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"dependencies": {
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"@nestjs/common": ">=7.4.0",
|
|
14
14
|
"@nestjs/core": ">=7.4.0",
|
|
15
|
-
"@sqb/builder": "^4.21.
|
|
16
|
-
"@sqb/connect": "^4.21.
|
|
15
|
+
"@sqb/builder": "^4.21.1",
|
|
16
|
+
"@sqb/connect": "^4.21.1",
|
|
17
17
|
"reflect-metadata": "^0.2.2",
|
|
18
18
|
"rxjs": ">=6.6.0"
|
|
19
19
|
},
|
package/sqb-core.module.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, Logger, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
3
|
import type { SqbModuleAsyncOptions, SqbModuleOptions } from './sqb.interface.js';
|
|
4
4
|
export declare class SqbCoreModule implements OnApplicationShutdown {
|
|
5
5
|
private readonly options;
|
|
6
6
|
private readonly moduleRef;
|
|
7
|
-
|
|
7
|
+
private logger?;
|
|
8
|
+
constructor(options: SqbModuleOptions, moduleRef: ModuleRef, logger?: Logger | undefined);
|
|
8
9
|
static forRoot(options?: SqbModuleOptions): DynamicModule;
|
|
9
10
|
static forRootAsync(options: SqbModuleAsyncOptions): DynamicModule;
|
|
11
|
+
onApplicationBootstrap(): Promise<void> | undefined;
|
|
10
12
|
onApplicationShutdown(): Promise<void>;
|
|
11
13
|
private static createAsyncProviders;
|
|
12
14
|
private static createAsyncOptionsProvider;
|
package/sqb-core.module.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var SqbCoreModule_1;
|
|
2
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
-
import { Global, Inject, Module, } from '@nestjs/common';
|
|
3
|
+
import { Global, Inject, Logger, Module, } from '@nestjs/common';
|
|
4
4
|
import { ModuleRef } from '@nestjs/core';
|
|
5
5
|
import { SqbClient } from '@sqb/connect';
|
|
6
6
|
import * as crypto from 'crypto';
|
|
@@ -12,9 +12,11 @@ import { getSQBToken, handleRetry } from './sqb.utils.js';
|
|
|
12
12
|
let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
13
13
|
options;
|
|
14
14
|
moduleRef;
|
|
15
|
-
|
|
15
|
+
logger;
|
|
16
|
+
constructor(options, moduleRef, logger) {
|
|
16
17
|
this.options = options;
|
|
17
18
|
this.moduleRef = moduleRef;
|
|
19
|
+
this.logger = logger;
|
|
18
20
|
}
|
|
19
21
|
static forRoot(options = {}) {
|
|
20
22
|
const optionsProvider = {
|
|
@@ -35,6 +37,12 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
35
37
|
provide: SQB_CONNECTION_OPTIONS,
|
|
36
38
|
useValue: getSqbConfig(options.useValue || {}, options.envPrefix),
|
|
37
39
|
},
|
|
40
|
+
{
|
|
41
|
+
provide: Logger,
|
|
42
|
+
useValue: typeof options.logger === 'string'
|
|
43
|
+
? new Logger(options.logger)
|
|
44
|
+
: options.logger,
|
|
45
|
+
},
|
|
38
46
|
],
|
|
39
47
|
exports: [connectionProvider],
|
|
40
48
|
};
|
|
@@ -60,10 +68,28 @@ let SqbCoreModule = SqbCoreModule_1 = class SqbCoreModule {
|
|
|
60
68
|
provide: SQB_MODULE_ID,
|
|
61
69
|
useValue: crypto.randomUUID(),
|
|
62
70
|
},
|
|
71
|
+
{
|
|
72
|
+
provide: Logger,
|
|
73
|
+
useValue: typeof options.logger === 'string'
|
|
74
|
+
? new Logger(options.logger)
|
|
75
|
+
: options.logger,
|
|
76
|
+
},
|
|
63
77
|
],
|
|
64
78
|
exports: [connectionProvider],
|
|
65
79
|
};
|
|
66
80
|
}
|
|
81
|
+
onApplicationBootstrap() {
|
|
82
|
+
const client = this.moduleRef.get(getSQBToken(this.options.name));
|
|
83
|
+
const op = this.moduleRef.get(SQB_CONNECTION_OPTIONS);
|
|
84
|
+
if (this.options.lazyConnect)
|
|
85
|
+
return;
|
|
86
|
+
this.logger?.log(`Connecting to database [${op.database}] at ${op.host}:${op.port} using ${op.dialect} dialect`);
|
|
87
|
+
Logger.flush();
|
|
88
|
+
return client.test().catch(e => {
|
|
89
|
+
this.logger?.error(`${op.dialect} connection failed: ` + e.message);
|
|
90
|
+
throw e;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
67
93
|
async onApplicationShutdown() {
|
|
68
94
|
const client = this.moduleRef.get(getSQBToken(this.options.name));
|
|
69
95
|
const op = this.moduleRef.get(SQB_CONNECTION_OPTIONS);
|
|
@@ -121,6 +147,7 @@ SqbCoreModule = SqbCoreModule_1 = __decorate([
|
|
|
121
147
|
Global(),
|
|
122
148
|
Module({}),
|
|
123
149
|
__param(0, Inject(SQB_MODULE_OPTIONS)),
|
|
124
|
-
__metadata("design:paramtypes", [Object, ModuleRef
|
|
150
|
+
__metadata("design:paramtypes", [Object, ModuleRef,
|
|
151
|
+
Logger])
|
|
125
152
|
], SqbCoreModule);
|
|
126
153
|
export { SqbCoreModule };
|
package/sqb.interface.d.ts
CHANGED