@elsikora/nestjs-typeorm-aws-connector 1.2.1 → 1.2.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/README.md +102 -101
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +93 -93
package/README.md
CHANGED
|
@@ -39,33 +39,33 @@ Example of both modules working together:
|
|
|
39
39
|
|
|
40
40
|
```typescript
|
|
41
41
|
@Module({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
imports: [
|
|
43
|
+
// First, configure Parameter Store
|
|
44
|
+
ParameterStoreConfigModule.registerAsync({
|
|
45
|
+
imports: [ConfigModule],
|
|
46
|
+
inject: [ConfigService],
|
|
47
|
+
useFactory: (config: ConfigService) => ({
|
|
48
|
+
application: config.get<string>("APPLICATION"),
|
|
49
|
+
config: {
|
|
50
|
+
region: config.get<string>("AWS_REGION"),
|
|
51
|
+
},
|
|
52
|
+
decryptParameters: true,
|
|
53
|
+
environment: config.get<string>("ENVIRONMENT"),
|
|
54
|
+
recursiveLoading: true,
|
|
55
|
+
}),
|
|
56
|
+
}),
|
|
57
|
+
// Then, configure Database module
|
|
58
|
+
TypeOrmAwsConnectorModule.registerAsync({
|
|
59
|
+
imports: [ConfigModule],
|
|
60
|
+
inject: [ConfigService],
|
|
61
|
+
useFactory: async () => ({
|
|
62
|
+
connectionTimeoutMs: 30_000,
|
|
63
|
+
databaseName: "app",
|
|
64
|
+
entities: [Bank],
|
|
65
|
+
// ... other options
|
|
66
|
+
}),
|
|
67
|
+
}),
|
|
68
|
+
],
|
|
69
69
|
})
|
|
70
70
|
export class AppModule {}
|
|
71
71
|
```
|
|
@@ -78,16 +78,16 @@ NestJS-TypeORM-AWS-Connector is a powerful integration module that provides seam
|
|
|
78
78
|
|
|
79
79
|
## Features
|
|
80
80
|
|
|
81
|
-
|
|
|
82
|
-
|
|
83
|
-
| 🔄
|
|
84
|
-
| 🏊
|
|
85
|
-
| ⚡️ | **Performance**
|
|
86
|
-
| 🔧
|
|
87
|
-
| 🎯
|
|
88
|
-
| 📊
|
|
89
|
-
| 🔍
|
|
90
|
-
| 🔄
|
|
81
|
+
| | Feature | Description |
|
|
82
|
+
| --- | ----------------------- | -------------------------------------------------------------------------------------------------- |
|
|
83
|
+
| 🔄 | **Connection Rotation** | Automatic connection rotation to prevent stale connections and ensure optimal database performance |
|
|
84
|
+
| 🏊 | **Connection Pooling** | Configurable connection pool with customizable size and timeout settings |
|
|
85
|
+
| ⚡️ | **Performance** | Optimized database connections with configurable timeouts and idle connection management |
|
|
86
|
+
| 🔧 | **Easy Configuration** | Flexible configuration options through both static and async module registration |
|
|
87
|
+
| 🎯 | **Type Safety** | Full TypeScript support with strong typing for all configuration options |
|
|
88
|
+
| 📊 | **Multiple Databases** | Support for different database types (PostgreSQL, MySQL, etc.) through EDatabaseType enum |
|
|
89
|
+
| 🔍 | **Verbose Logging** | Optional verbose mode for detailed logging of database operations |
|
|
90
|
+
| 🔄 | **Auto-Sync Schema** | Optional automatic schema synchronization with database |
|
|
91
91
|
|
|
92
92
|
## Installation
|
|
93
93
|
|
|
@@ -100,30 +100,30 @@ npm install @elsikora/nestjs-typeorm-aws-connector
|
|
|
100
100
|
### Async Configuration
|
|
101
101
|
|
|
102
102
|
```typescript
|
|
103
|
-
import { TypeOrmAwsConnectorModule, EDatabaseType } from
|
|
103
|
+
import { TypeOrmAwsConnectorModule, EDatabaseType } from "@elsikora/nestjs-typeorm-aws-connector";
|
|
104
104
|
|
|
105
105
|
@Module({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
106
|
+
imports: [
|
|
107
|
+
TypeOrmAwsConnectorModule.registerAsync({
|
|
108
|
+
imports: [ConfigModule],
|
|
109
|
+
inject: [ConfigService],
|
|
110
|
+
useFactory: async () => ({
|
|
111
|
+
connectionTimeoutMs: 30_000,
|
|
112
|
+
databaseName: "app",
|
|
113
|
+
entities: [Bank],
|
|
114
|
+
idleTimeoutMs: 30_000,
|
|
115
|
+
isVerbose: true,
|
|
116
|
+
poolSize: 10,
|
|
117
|
+
port: 5432,
|
|
118
|
+
rotation: {
|
|
119
|
+
intervalMs: 5000,
|
|
120
|
+
isEnabled: true,
|
|
121
|
+
},
|
|
122
|
+
shouldSynchronize: true,
|
|
123
|
+
type: EDatabaseType.POSTGRES,
|
|
124
|
+
}),
|
|
125
|
+
}),
|
|
126
|
+
],
|
|
127
127
|
})
|
|
128
128
|
export class AppModule {}
|
|
129
129
|
```
|
|
@@ -131,49 +131,48 @@ export class AppModule {}
|
|
|
131
131
|
### Static Configuration
|
|
132
132
|
|
|
133
133
|
```typescript
|
|
134
|
-
import {TypeOrmAwsConnectorModule, EDatabaseType} from
|
|
134
|
+
import { TypeOrmAwsConnectorModule, EDatabaseType } from "@elsikora/nestjs-typeorm-aws-connector";
|
|
135
135
|
|
|
136
136
|
@Module({
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
137
|
+
imports: [
|
|
138
|
+
TypeOrmAwsConnectorModule.register({
|
|
139
|
+
connectionTimeoutMs: 30_000,
|
|
140
|
+
databaseName: "app",
|
|
141
|
+
entities: [Bank],
|
|
142
|
+
idleTimeoutMs: 30_000,
|
|
143
|
+
isVerbose: true,
|
|
144
|
+
poolSize: 10,
|
|
145
|
+
port: 5432,
|
|
146
|
+
rotation: {
|
|
147
|
+
intervalMs: 5000,
|
|
148
|
+
isEnabled: true,
|
|
149
|
+
},
|
|
150
|
+
shouldSynchronize: true,
|
|
151
|
+
type: EDatabaseType.POSTGRES,
|
|
152
|
+
}),
|
|
153
|
+
],
|
|
154
154
|
})
|
|
155
|
-
export class AppModule {
|
|
156
|
-
}
|
|
155
|
+
export class AppModule {}
|
|
157
156
|
```
|
|
158
157
|
|
|
159
158
|
### Integration with TypeORM
|
|
160
159
|
|
|
161
160
|
```typescript
|
|
162
|
-
import { TypeOrmModule } from
|
|
163
|
-
import { TypeOrmAwsConnectorService } from
|
|
161
|
+
import { TypeOrmModule } from "@nestjs/typeorm";
|
|
162
|
+
import { TypeOrmAwsConnectorService } from "@elsikora/nestjs-typeorm-aws-connector";
|
|
164
163
|
|
|
165
164
|
@Module({
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
165
|
+
imports: [
|
|
166
|
+
TypeOrmModule.forRootAsync({
|
|
167
|
+
inject: [TypeOrmAwsConnectorService],
|
|
168
|
+
useFactory: async (databaseService: TypeOrmAwsConnectorService) => {
|
|
169
|
+
const options = await databaseService.getTypeOrmOptions();
|
|
170
|
+
return {
|
|
171
|
+
...options,
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
175
|
+
],
|
|
177
176
|
})
|
|
178
177
|
export class AppModule {}
|
|
179
178
|
```
|
|
@@ -181,7 +180,7 @@ export class AppModule {}
|
|
|
181
180
|
## Configuration Options
|
|
182
181
|
|
|
183
182
|
| Option | Type | Required | Default | Description |
|
|
184
|
-
|
|
183
|
+
| -------------------- | --------------------- | -------- | --------------------------- | -------------------------------------------- |
|
|
185
184
|
| type | EDatabaseType | Yes | - | Database type (POSTGRES, MYSQL, etc.) |
|
|
186
185
|
| databaseName | string | Yes | - | Name of the database to connect to |
|
|
187
186
|
| port | number | Yes | - | Database port number |
|
|
@@ -201,8 +200,8 @@ The module supports multiple database types through the `EDatabaseType` enum:
|
|
|
201
200
|
|
|
202
201
|
```typescript
|
|
203
202
|
enum EDatabaseType {
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
POSTGRES = "postgres",
|
|
204
|
+
MYSQL = "mysql",
|
|
206
205
|
}
|
|
207
206
|
```
|
|
208
207
|
|
|
@@ -227,16 +226,18 @@ The module includes built-in error handling for common database connection issue
|
|
|
227
226
|
## Best Practices
|
|
228
227
|
|
|
229
228
|
1. **Connection Pooling**
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
|
|
230
|
+
- Set appropriate `poolSize` based on your application's needs
|
|
231
|
+
- Monitor pool usage in production
|
|
232
232
|
|
|
233
233
|
2. **Connection Rotation**
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
|
|
235
|
+
- Enable rotation for long-running applications
|
|
236
|
+
- Adjust `rotation.intervalMs` based on your workload
|
|
236
237
|
|
|
237
238
|
3. **Timeouts**
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
- Set reasonable `connectionTimeoutMs` and `idleTimeoutMs`
|
|
240
|
+
- Consider your application's specific requirements
|
|
240
241
|
|
|
241
242
|
## Contributing
|
|
242
243
|
|