@mikro-orm/nestjs 4.3.0 → 4.3.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 +17 -0
- package/mikro-orm.common.js +3 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -300,6 +300,23 @@ export class MyService {
|
|
|
300
300
|
}
|
|
301
301
|
```
|
|
302
302
|
|
|
303
|
+
## App shutdown and cleanup
|
|
304
|
+
|
|
305
|
+
By default, NestJS does not listen for system process termination signals (for example SIGTERM). Because of this, the MikroORM shutdown logic will never executed if the process is terminated, which could lead to database connections remaining open and consuming resources. To enable this, the `enableShutdownHooks` function needs to be called when starting up the application.
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
async function bootstrap() {
|
|
309
|
+
const app = await NestFactory.create(AppModule);
|
|
310
|
+
|
|
311
|
+
// Starts listening for shutdown hooks
|
|
312
|
+
app.enableShutdownHooks();
|
|
313
|
+
|
|
314
|
+
await app.listen(3000);
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
More information about [enableShutdownHooks](https://docs.nestjs.com/fundamentals/lifecycle-events#application-shutdown)
|
|
319
|
+
|
|
303
320
|
## Testing
|
|
304
321
|
|
|
305
322
|
The `nestjs-mikro-orm` package exposes `getRepositoryToken()` function that returns prepared token based on a given entity to allow mocking the repository.
|
package/mikro-orm.common.js
CHANGED
|
@@ -19,9 +19,11 @@ function UseRequestContext() {
|
|
|
19
19
|
if (!(context.orm instanceof core_1.MikroORM)) {
|
|
20
20
|
throw new Error('@UseRequestContext() decorator can only be applied to methods of classes that carry `orm: MikroORM`');
|
|
21
21
|
}
|
|
22
|
+
let result;
|
|
22
23
|
await core_1.RequestContext.createAsync(context.orm.em, async () => {
|
|
23
|
-
await originalMethod.apply(context, args);
|
|
24
|
+
result = await originalMethod.apply(context, args);
|
|
24
25
|
});
|
|
26
|
+
return result;
|
|
25
27
|
};
|
|
26
28
|
return descriptor;
|
|
27
29
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/nestjs",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Dario Mancuso",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"lint": "eslint src/**/*.ts"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@mikro-orm/core": "^4.0.0",
|
|
44
|
+
"@mikro-orm/core": "^4.0.0||^5.0.0-dev.0",
|
|
45
45
|
"@nestjs/common": "^7.0.0||^8.0.0",
|
|
46
46
|
"@nestjs/core": "^7.0.0||^8.0.0"
|
|
47
47
|
},
|